Laravel - Application Structure

Laravel - Application Structure

The structure of an application in Laravel is basically the structure of folders, subfolders, and files included in a project. Once we create a project in Laravel, we will get an overview of the application structure as shown in the picture here.

The snapshot shown here is from the root folder of Laravel, namely laravel-project . It includes various subfolders and files. The analysis of folders and files and their functional aspects are given below −

Appendix

This is the application folder and includes all project source code. It contains events, exceptions, and a middleware declaration. Application folder contains various subfolders as described below −

Prefix

The console includes the craft commands needed for Laravel. It includes a directory named Commands where all commands are declared with an appropriate signature. The Kernal.php file calls the commands declared in Inspire.php .

If we need to call a specific command in Laravel, then we must make the appropriate changes to this directory.

Events

This folder includes all events for the project.

Events are used to trigger actions, detect errors or necessary checks, and provide more flexibility. Laravel stores all events in one directory. By default , the event.php file is included, which declares all the main events.

Exceptions

This folder contains all the methods required for exception handling. It also contains a handle.php file which handles all exceptions.

http

The Http folder has subfolders for controllers, middleware, and application requests. Because Laravel follows the MVC design pattern, this folder includes the model, controllers, and views defined for specific directories.

The middleware subfolder includes a middleware engine including a filtering mechanism and a relationship between a response and a request.

The Requests subfolder includes all application requests.

work

The Jobs directory maintains the actions queued for the Laravel application. The base class is shared across all jobs and provides a central location to place them all under one roof.

Listeners

Listeners are specific to the event and include methods that are used to handle events and exceptions. For example, a declared login event includes a LoginListener event .

policies

Policies are PHP classes that include authorization logic. Laravel includes a feature to create all authorization logic in policy classes inside this subfolder.

Providers

This folder contains all the service providers needed to register events for the core servers and to configure the Laravel application.

bootstrap

This folder contains all application bootstrap scripts. It contains a subfolder, namely cache , which includes all files related to web application caching. You can also find the app.php file , which initializes the scripts required for bootstrap.

config

The config folder includes various configurations and related settings required for a Laravel application to run smoothly. Various files included in the config folder as shown in the picture here. The filenames work according to the functionality associated with them.

Database

As the name suggests, this directory includes various options for database functions. It includes three sub-directories as given below −

  • Seeds. Contains the classes used for the unit test database.

  • Migrations - This folder helps in database migration requests used in the web application.

  • Factories - This folder is used to generate a large number of data records.

Seeds. Contains the classes used for the unit test database.

Migrations - This folder helps in database migration requests used in the web application.

Factories - This folder is used to generate a large number of data records.

public

This is the root folder which helps in initializing the Laravel application. It includes the following files and folders −

  • .htaccess - this file specifies the server configuration.

  • javascript and css - these files are considered assets.

  • index.php - This file is required to initialize the web application.

.htaccess - this file specifies the server configuration.

javascript and css - these files are considered assets.

index.php - This file is required to initialize the web application.

Resources

The resource directory contains files that enhance your web application. Subfolders included in this directory and their purpose is explained below −

  • assets - The assets folder contains files such as LESS and SCSS that are needed to style the web application.

  • lang - This folder contains configuration for localization or internalization.

  • Views − Views are HTML files or templates that interact with end users and play a major role in

    • MVC architecture.

    assets - The assets folder contains files such as LESS and SCSS that are needed to style the web application.

    lang - This folder contains configuration for localization or internalization.

    Views − Views are HTML files or templates that interact with end users and play a major role in MVC architecture.

    Note that the resource directory will be flat, not a resource folder. An illustrated image of the same is shown below −

Storage

This is the folder that stores all the logs and necessary files that are often needed when running a Laravel project. The subfolders included in this directory and their purpose are given below −

  • app - This folder contains files that are called sequentially.

  • Framework - contains sessions, cache and views that are frequently called.

  • Logs - All exceptions and error logs are tracked in this subfolder.

app - This folder contains files that are called sequentially.

Framework - contains sessions, cache and views that are frequently called.

Logs - All exceptions and error logs are tracked in this subfolder.

tests

All unit test examples are included in this directory. The naming convention for naming test case classes is camel_case and follows the convention according to the functionality of the class.

salesman

Laravel is completely based on Composer dependencies, for example, to install the Laravel installer, or to include third party libraries, etc. The Vendor folder includes all composer dependencies.

In addition to the above files, Laravel also includes some other files that play a major role in various features such as GitHub configuration, packages, and third party libraries.

The files included in the application structure are shown below −