Fatal error: Call to undefined function asset() in C:\wamp\www\laravel-master\app\views\hello.php
10,036
Solution 1
I'm using Laravel version 5.2
and I've no problem using this :
<!-- JavaScripts -->
<script src="{{ asset('js/main.js') }}"></script>
Solution 2
Change this part:
<?php echo asset('css/main.css'); ?>
as this:
/css/main.css
Solution 3
You can try to do it like {{ HTML::style('css/main.css') }}
Solution 4
Note that you can use pure HTML:
<link rel="stylesheet" type="text/css" href="/css/main.css" >
Author by
Javad
Updated on June 04, 2022Comments
-
Javad about 2 years
I wanted to learn laravel framework. I could install laravel in my webserver(Wamp) and i get some tutorial to learn it but when i tryed to add style to 'h1' tag in the hello.php file place in this path:("C:\wamp\www\laravel-master\app\views\hello.php") by asset() function, above mentioned error occurred. please help me to find out where the problem are. here is hello.php codes:
<style> body { margin:0; font-family:'Lato', sans-serif; text-align:center; color: #999; } .welcome { width: 300px; height: 200px; position: absolute; left: 50%; top: 50%; margin-left: -150px; margin-top: -100px; } a, a:visited { text-decoration:none; } h1 { font-size: 32px; margin: 16px 0 0 0; } </style> </head> <link rel="stylesheet" type="text/css" href="<?php echo asset('css/main.css'); ?>" > <body> <div class="welcome"> <a href="http://laravel.com" title="Laravel PHP Framework"> <img src="some_long_src" alt="Laravel PHP Framework"></a> <h1 class="highlight">You have arrived.</h1> </div> </body> </html>
and main.css :
.highlight { border: solid 2px #F00; }
and my laravel version is 4.2.16.
thanks in advance.
-
Alupotha about 9 yearsI think
asset('css/main.css');
is correct, problem is asset() method is undefined ! -
KyleK about 9 yearsOnly with hello.blade.php, not hello.php. Here it seem blade is not used.
-
KyleK about 9 yearsMaybe motto would say: do not use PHP, juste put /css/main.css in the link tag.
-
mirza about 9 yearsi think this is duplicate of my answer
-
KyleK about 9 yearsI did not know if you would say asset('/css/main.css') or just /css/main.css
-
Javad about 9 yearsright, but i think it's better to find the problem.
-
apelsinka223 about 9 yearsThis is analog of
<link rel="stylesheet" type="text/css" href="css/main.css" >
in blade.