Laravel Folder Structure

Laravel Folder Structure

Share and Enjoy !

0Shares
0

In this post, we will discuss the folder structure and their role in the application. Laravel Folder Structure created in such a way that it is suitable for all types of small and large projects. Hence best part of the Laravel framework, that it allows a developer to create your own Laravel Folder Structure. In other words, there is no compulsion on Application structure, Only we have to look to the composer to autoload all our classes.

Project Root Directory

App Directory

The first directory in the Laravel Folder Structure is the App folder.  It is an important folder because it contains the core code of Laravel Application. Therefore all the important classes of the project reside in this folder. App folder has subdirectories like console, HTTP, Exception, Models and Providers which used to handle the exception and build the application.

Bootstrap Directory

Next directory in the Laravel Folder Structure is Bootstrap. This bootstrap folder is totally different from Bootstrap CSS. This folder is responsible for framework starting and functioning correctly. Bootstrap contains app.php file, which is managed to autoload framework. It also stores framework generated cash file in cache folder which extend performance optimization.

Config Directory

This folder helps you to control and understand the framework. As per the name, this directory stored all the files which used to configure OR set up the project environment. For example, if a developer wants to debug then he needs to enable debug mode in the app.php file. Another file called database.php which access all variables from the .env file for the database functionality. So we will study it in another blog post.

Database Directory

This folder stored all database functionality related files. It has three sub-directories .i.e Factories, Migrations and seeders. For example, if a developer wants to change database structure then with the help of artisan command i.e. php artisan make:migration generate migration file. Thus this migration file will take care of it.

Public Directory

The public directory is the entry point of your web application. Therefore this folder also stores WEB assets which the browser will access directly like images, JavaScript, CSS and other files. This means your domain should point to this folder. Hence Index.php will receive all requests and will initialize the process of autoloading events.

Resource Directory

This folder stores all un-compiled files like LESS, SCSS or JavaScript in the js and CSS respectively. And If your application is developing for multilingual then the lang folder stores all language files.  

View is one of the essential folders of the Laravel Folder Structure. View folder is a subfolder of resource directory and it stores HTML presentations logic. Laravel uses its own blade templating engine. It is a simple but powerful system so you can create sections in your view and inherits layouts from other layout template files.

Route Directory

The route is one of the important folders of Laravel. Here developer will define URL for web requests and route for it. Laravel installation creates some default route files like web.php, api.php, channels.php and console.php in the route directory. But Laravel also allows a developer to create custom route files as per project requirements.

Now let’s look at the first file web.php in the route folder. All the requests for a web application, handled by web.php route file and it auto-loaded by app/Providers/RouteServiceProvider.php. This route file is a member of a web middleware group, so it is responsible for providing features like a session state, protection from cross-site request forgery attacks, cookies etc. 

Next file is api.php, it is also auto-loaded by app/Providers/RouteServiceProvider.php and kept in the API middleware group. Hence it is responsible to provide stateless to avoid tracking transactions. Basically, the route set up to secure and verify transactions using a token system and restrict access to session state.

The console.php file allows the developer to define Closure based Artisan Commands. Earlier for such commands need to define the class, after that register it in the console kernel. We will learn more about it some other post.

The channel.php helps you to define and register broadcasting channels which our application is going to use.

Storage Directory

This storage folder stored cache, session and compiled files generated by the framework. So storage folder has three subfolders app, framework and logs which stored files accordingly names. App directory stores files which are generated by applications like user-profiles and other details which are publicly available. Framework directory stored all files generated by the laravel framework like templates, file-based sessions and cache. Log directory stored all log generated by the application.

Test Directory

The test directory saves our automated tests. A developer can run all tests using an artisan command which generates the most detailed results.

Vendor Directory

Laravel application works with many libraries and composer for dependency management. Hence Vendor folder stores composer dependencies and packages.

Learn how to

We hope you understand the Laravel Folder Structure. We discussed the folder structure and their roles. This post will help you in your development. You can find the community on laravel.io, Laracasts Discuss, LaraChat, Discord, Reddit and laracon.net.

Visit our another Laravel Post

Share and Enjoy !

0Shares
0

Leave a Reply