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" >
Share:
10,036
Javad
Author by

Javad

Updated on June 04, 2022

Comments

  • Javad
    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
    Alupotha about 9 years
    I think asset('css/main.css'); is correct, problem is asset() method is undefined !
  • KyleK
    KyleK about 9 years
    Only with hello.blade.php, not hello.php. Here it seem blade is not used.
  • KyleK
    KyleK about 9 years
    Maybe motto would say: do not use PHP, juste put /css/main.css in the link tag.
  • mirza
    mirza about 9 years
    i think this is duplicate of my answer
  • KyleK
    KyleK about 9 years
    I did not know if you would say asset('/css/main.css') or just /css/main.css
  • Javad
    Javad about 9 years
    right, but i think it's better to find the problem.
  • apelsinka223
    apelsinka223 about 9 years
    This is analog of <link rel="stylesheet" type="text/css" href="css/main.css" > in blade.