If you are a beginner in Laravel and you are about to deploy and make your first application, it is a must that you must know its application structure. In this blog, we will show and briefly explain its structure which is, basically the structure of folders, sub-folders and files included in a project.
Once we created a project in Laravel, we will get an overview for its application structure as shown below. The root folder of the Laravel project contains a numerous subfolders and files.
It’s the project’s application folder, which contains all of the project’s source code. It includes declarations for events, exceptions, and middleware. The app subdirectory is divided into several subfolders, as shown below.
- Console – The artisan commands required by Laravel are available in the console. It includes a directory called Commands, which contains a list of all the commands and their signatures. Kernal.php executes the commands defined in Inspire.php. If we need to call a specific command in Laravel, then we should make appropriate changes in this directory.
- Exceptions – This category contains all of the exception-handling methods. It also includes the handle.php file, which handles all exceptions.
- Http – Controllers, middleware, and application requests are all subfolders of the Http subdirectory. This folder contains model, controllers, and views created for the specific directories, as Laravel uses the MVC design pattern. The Middleware sub-folder contains the middleware mechanism, which comprises the filter mechanism and response and request communication. All of the application’s requests are in the Request Folder.
- Models – Each database table has a “Model” associated with it that is utilized to communicate with it. Models enable you to query your tables for data as well as add new records to the database.
- Providers – All of the service providers for your application are included in the Providers directory. Service providers prepare your application for incoming requests by binding services in the service container, registering events, and executing any other actions necessary.
The app.php file in the bootstrap directory bootstraps the framework. This directory also contains a cache directory, which contains framework-generated performance files such the route and services cache files. You shouldn’t need to change any of the files in this directory very often.
The config directory includes all of your application’s configuration files, as the name implies. Reading over all of these files and becoming familiar with all of the options available to you is a terrific idea.
Your database migrations, model factories, and seeds are all stored in the database directory. You can also use this directory to store a SQLite database if you want.
- Factories – This folder is used to generate large number of data records.
- Migrations – This folder helps in queries for migrating the database used in the web application.
- Seeders – This contains the classes used for unit testing database.
- Assets − The assets folder include files such as LESS and SCSS, that are required for styling the web application.
- Lang − This folder includes configuration for localization or internalization.
- Views − Views are the HTML files or templates which interact with end users and play a primary role in MVC architecture.
The routes directory holds all of your application’s route definitions. Laravel comes with many route files by default: web.php, api.php, console.php, and channels.php.
- web.php – The RouteServiceProvider places routes in the web middleware group, which offers session state, CSRF protection, and cookie encryption, in the web.php file. If your application does not provide a stateless, RESTful API, all of your routes will almost certainly be defined in the web.php file.
- api.php – The RouteServiceProvider adds routes to the api middleware group in the api.php file. These routes are designed to be stateless, which means that requests entering the application through them will be authenticated using tokens and will not have access to session state.
- channels.php – You can register all of the event broadcasting channels that your application supports in the channels.php file.
- console.php – You can define all of your closure-based console commands in the console.php file. Each closure is associated with a command instance, allowing for a straightforward way to communicate with the IO methods of each command. This file defines console-based entry points (routes) into your program, despite the fact that it does not create HTTP routes.
Your logs, compiled blade templates, file-based sessions, file caches, and other files generated by the framework are all stored under the storage directory. This directory is divided into three sections: app, framework, and logs. Any files generated by your program can be stored in the app directory. Framework produced files and caches are stored in the framework directory. The logs directory includes the log files for your application.
Your automated tests are stored in the tests directory. Out of the package, PHPUnit unit tests and feature tests are included. The term Test should be appended to each test class. You can use the phpunit or php vendor/bin/phpunit commands to perform your tests. Alternatively, you can use the php artisan test to create a more detailed and appealing display of your test findings.
In addition to the above mentioned files, Laravel also includes some other files which play a primary role in various functionalities such as GitHub configuration, packages and third party libraries. These files are shown below