3

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.

Javad
  • 41
  • 1
  • 2
  • 6
  • What is the exact error throwed? – KyleK Apr 18 '15 at 12:14
  • says that asset() function is undefined. – Javad Apr 18 '15 at 12:16
  • It seem your PHP template is not managed by the Laravel view engine. How do you return the view in your controller? – KyleK Apr 18 '15 at 12:20
  • your mind if i change my laravel version and then install again it, problem will solve? what about it's new version(ex laravel 5)? – Javad Apr 18 '15 at 12:22
  • how can i return my view? if we seem your guess is right what do you suggest me to do? – Javad Apr 18 '15 at 13:39
  • No, I think you call directly your view instead of calling your controller first. Maybe you misunderstood the view-controller system. Please see the routes and the controller parts of the documentation, or show us your controller code and your routes.php – KyleK Apr 18 '15 at 15:33
  • In fact, now, I guess you bypass laravel. You must have a route /myurl to point to MyController@myMethod and this method must call view("hello"). See the doc. – KyleK Apr 18 '15 at 15:53

5 Answers5

3

I'm using Laravel version 5.2

and I've no problem using this :

  <!-- JavaScripts -->
    <script src="{{ asset('js/main.js') }}"></script>
Gujarat Santana
  • 9,854
  • 17
  • 53
  • 75
1

Change this part:

<?php  echo asset('css/main.css'); ?>

as this:

/css/main.css
mirza
  • 5,685
  • 10
  • 43
  • 73
1

You can try to do it like {{ HTML::style('css/main.css') }}

apelsinka223
  • 512
  • 3
  • 15
1

Note that you can use pure HTML:

<link rel="stylesheet" type="text/css" href="/css/main.css" >
KyleK
  • 4,643
  • 17
  • 33
0

Today I've run in the same strange situation. A blade file with standard bootstrap & jquery links working fine as usual, when added fullcalendar fires that error. Removing fullcalendar works fine again, adding fullcalendar, error again. It makes no sense to me because there is no 404 error, just "Call to undefined function asset()"

I've tried replacing asset() with url() and everything works as expected.

Farid
  • 542
  • 5
  • 16