Laravel 8 Application structure

Last updated Jan 31, 2022

You may have noticed that a number of folders and files are generated in your application folder after installing the composer and creating your first Laravel  application. If you are a beginner, you might wonder what these folders are and their functions. This chapter will discuss the structures and functions of directories and files in a Laravel 8 application

Laravel adheres to the MVC architecture.  The acronym MVC stands for "Model View Controller" and is used when building apps. With this architectural model, domains, applications, business logic, and interfaces are separated. This means that the Laravel application is separated into three, the controller, the view and the model.

Let’s take a look at the Laravel MVC architecture:

 

Laravel MVC Architecture

 

Image-text: the Laravel MVC architecture

  • The model is used to manage important behaviors and application data. It mainly responds to the requests for information, responds to the instructions to change the information state or notify the observers in the event-driven systems after the information has been changed. This can be the system database or any other storage system. If you request data from a source or a database, then it is retrieved by the model.

  • The view is important as it displays what we see in the browser. It renders what is appropriate for users to see from the model. When you access a website, the View normally provides the web page that you see.

  • Controllers, on the other hand, receive user input and route it to model objects and views to perform the relevant actions or requests. When you click on a website, the controller processes your requests and compels the view and model to perform what you requested.

  • Finally, the route sends the path/route to a particular Laravel controller based on your actions on the webpage

Laravel Application structure

The screenshot below shows the Laravel application structure

Laravel8 application structure

 

A Laravel  app consists of several files directories and subdirectories in the root directory. They include:

  • App: The core code for the Laravel 8 application is stored in this directory. This directory contains the following sub-directories:

    • Console- All the custom Artisan commands  created using the make: command  are stored in this directory

    • Exceptions- This directory contains the application exception handler, and it handles all the exceptions thrown by the application.

    • Http- This directory stores all the application requests, middleware, and controllers

    • Models- This directory handles all the model files

    • Providers- This directory stores all the service providers for the application

  • Bootstrap: This directory contains Bootstrap files and configuration files for the application. It would be not easy to create stunning and responsive content without these files since we would have to write all CSS code from scratch.

  • Config: All application configuration files are stored in this folder. This directory also includes application migrations and seeds. You can also store your SQLite databases in this folder.

  • Database

    This directory includes different parameters for database functionalities, which includes three sub-directories

    • Seeds − This contains the classes used for unit testing database.

    • Migrations − This will be used in queries for migrating the database used in the web application.

    • Factories − This will be used to generate large number of data records.

  • Public: All application assets, such as images, CSS, and JS files, are kept in this directory. All of the application view files and SASS, LESS, CSS files, and lang directory are also housed in this directory. 

    • .htaccess − This will manage all  the server configuration.

    • javascript and css − These files we treat as assets.

    • index.php − To initialization of a web application we will use this file.

  • Application Routes: All the application routes are stored in this directory. There is also a php file in this directory that receives all the requests made to the application, redirecting the requests to the application controller methods.

  • Storage: The blade templates, session files, and application cache files are all stored here.

  • Tests: This directory contains all the application test files.

  • Vendor: This directory contains all application composer dependencies.

  • .env file: This directory contains all the configuration credentials, such as database configuration files and other third-party credentials.

  • .gitattribute-This file contains all the git information.

  • .gitignore: This file contains a list of all the files that will not be committed to the git repositories on bitbucket.

  • .artisan: This file is only triggered when the php artisan command is executed.

  • .composer.lock: This file secures the dependencies' versions.

  • Package.json: This file contains the dependencies for frontend development, such as jquery and vue.

  • Server.php: this file allows users to emulate Apache’s "Mod_rewrite" functionality from the built-in PHP web server.

  • Channels.php: This file allows the registration of the event broadcasting channels supported by our Laravel application.

  • Api.php: This file contains all the registered API routes for the application.

 

Conclusion

In this chapter, we have gone through the structures and functions of directories and files in a Laravel  application. In the following chapter, we'll learn how to configure our Laravel application

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

378 Views