5

I have just begun learning lumen and can't seem to find the answer to this simple question. This is my current <head>:

   <head>
    <title>Sharp notes!</title>
    <link rel="stylesheet" type="text/css" href="/assets/css/main.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
    </head>

This causes the following error:

[Sat Jun 17 20:13:09 2017] 127.0.0.1:56950 [200]: /
[Sat Jun 17 20:13:09 2017] 127.0.0.1:56952 [404]: /assets/css/main.css - No such file or directory

Please help!

Flame of udun
  • 2,136
  • 7
  • 35
  • 79

5 Answers5

3

You should put the css files in your public directory.

myApp/public/css/main.css

Then the asset helper should resolve the path correctly

{{ asset('/css/main.css') }}

Further explanation here:

https://laracasts.com/discuss/channels/general-discussion/asset-vs-url

Your assets (css, js, images, etc.) need to be placed in the application's public directory.

3

The solution : you need to use url('') ,

Because Lumen does not provide the asset helper function you may want to use url e.g.

The url function generates a fully qualified URL to the given path: Blade. More informations ir : Laravel Helpers url()

HOW TO :

With Blade :

<link rel="stylesheet" href="{{ url('/assets/css/main.css') }}">

With PHP :

<link rel="stylesheet" href="<?php url('/assets/css/main.css') ?>">

if you want you can create your own asset helper function of course, have a look here:

https://laracasts.com/discuss/channels/lumen/extend-helper-functions-to-lumen?page=0

or

How to do {{ asset('/css/app.css') }} in Lumen?

2

maybe it helps you try this

<link rel="stylesheet" type="text/css" href="{{ URL::asset('resources/assets/css/main.css') }}">
1

You can simply put your assets folder (containing img, libs, js and styles) into public folder & do the needful like like this. <img src="assets/img/visa.PNG">

0

In laravel lumen you don't have to define the public path . Put your assets into public folder and rest will automatically tracked. For more information visit https://lumen.laravel.com

fahim hasan
  • 38
  • 1
  • 9