Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.0 folder structure: public vs. resources

In Laravel 4.2, I used public folder to store all my CSS, JS, images and uploads. Currently, there's a new resources folder with assets folder in it coming with Laravel 5.0 installation:

/public
/resources/assets

This is confusing to me, especially because resources also holds views in it.

Via Laravel's upgrade guide (4.2 to 5.0):

Copy your application's public assets from your 4.2 application's public directory to your new application's public directory.

and further:

You may move your Sass, Less, or CoffeeScript to any location you wish. The resources/assets directory could be a good default location.

Question: What is the actual difference between public and resources folders in Laravel 5.0 folder structure?

like image 212
lesssugar Avatar asked Feb 13 '15 09:02

lesssugar


People also ask

What is resources folder in Laravel?

Laravel elixir, by default uses the /resources/assets folder as the base directory for scripts to be compiled, minified and so on. So you should put your raw sass, less, coffeescript, js and css files in there to let elixir do it's work. A good place for the files you are using is the public folder.

What is the purpose of a public folder in Laravel?

The files and folders in laravels public folder are meant to be web accessible. For security, all other files and folders in the laravel framework should not be web accessible.

Where is public folder in Laravel?

This lookup could be any folder on the server. Take for instance the following folder: /var/www/html/devdojo/ . The folder lookup location can be set up through the server or the hosting provider. If I had setup a Laravel app in my /var/www/html/devdojo/ folder and this is folder my server looks to serve up an index.

What is Laravel directory structure?

The storage directory contains your logs, compiled Blade templates, file based sessions, file caches, and other files generated by the framework. This directory is segregated into app , framework , and logs directories. The app directory may be used to store any files generated by your application.


1 Answers

The big difference here is that everything in public is... well public. resources aren't. What you put in where is up to you.

Generally you would have everything the browser needs to access directly in the public directory. Which usually means: JavaScript, CSS, images, maybe some videos or audio files.

resources/assets is meant for things that have to be compiled or minified first. So you would have a few LESS or SASS files in resources/assets and they would get compiled and minified into one CSS file that's put in the public directory.

like image 199
lukasgeiter Avatar answered Sep 24 '22 22:09

lukasgeiter