Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do javascript and css files go in a laravel project

Where should static javascript and css files in a Laravel 4 application. For the sake of my own understanding, I'm not interested in using any sort of assets or packages yet.

I tried putting them under public/js and public/packages to no avail, getting the following 404 errors in my page:

GET http://localhost/~myuser/mytest/packages/test2.js 404 (Not Found)
GET http://localhost/~myuser/mytest/js/mytest.js 404 (Not Found)

Here is what my .htaccess file looks like for reference:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /~myuser/mytest/public/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
like image 973
theycallmemorty Avatar asked Apr 05 '14 01:04

theycallmemorty


1 Answers

All assets should be placed in the public folder

public/js
public/css
public/fonts
public/images

You can access the assets using the asset() method or the Laravel HTML helper methods HTML::script and HTML::style. i.e to include Javascript file:

 - <script src="{{ asset('js/yourfile.js') }}"></script>

 - {{ HTML::script('js/yourfile.js') }}

Hope this helps!

like image 180
dev7 Avatar answered Oct 14 '22 09:10

dev7