Home  >  Q&A  >  body text

How to reference static files in templates in laravel 5.2?

My demo.css is placed in public/css/demo.css

<link rel="stylesheet" href="{{asset('css/demo.css')}}">

If you quote like this, 404 will appear if you enter directly from the server.php entry. It is found that the generated link is:

..../server.php/css/demo.css

If accessed from public/index.php this is correct, the generated link is:

..../public/css/demo.css

How do you reference your static files? ? ?
Which entrance is generally used to access the website? ? ?

By the way, my server environment is: wampServer

PHP中文网PHP中文网2713 days ago477

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:54:47

    The laravel service root directory is public, so you need to put the css file public/css中,然后再用asset()辅助函数。
    我一般是在resource文件夹中放置静态文件,然后通过gulpcopy()into the directory corresponding to public

    reply
    0
  • PHPz

    PHPz2017-05-16 16:54:47

    You can copy the .htaccess file under public to the project root directory, and then change server.php to index.php to access it. To introduce css files and js files, use {{asset('path') }}.

    reply
    0
  • Cancelreply