Laravel 5.0 folder structure: public vs. resources

2020-02-02 07:44发布

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?

4条回答
放荡不羁爱自由
2楼-- · 2020-02-02 08:26

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.

When working this way, you can have all your files concatenated and minified with gulp and less effort. Simply include them from your public folder.

查看更多
甜甜的少女心
3楼-- · 2020-02-02 08:36

You can think of them as being separate folders for development and production. In resources you have all your development files that'll not ship off into production (SASS, Coffeescript, Babel, Jade, etc). But when they're compiled (or piped through something like Gulp) you can configure them to output to public, the production folder.

查看更多
何必那么认真
4楼-- · 2020-02-02 08:37

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.

查看更多
甜甜的少女心
5楼-- · 2020-02-02 08:45

In laravel public folder is best for Image, CSS, and Javascripts. In public folder we can use for uploaded images, videos, text files etc.

查看更多
登录 后发表回答