Laravel Directory Structure


Laravel Directory Structure – Laravel directory structure is used to define where your directory is located.


Laravel Directory Structure.

Let us understand how to use directory structure.

Function:-

There are some followings function to describe directory structure.

  • 1. Introduction.
  • 2. The Root Directory.
  • 3. The App Directory.

1. Introduction.

The default laravel application structure is intended to provide a great starting point for both large and small application. You are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located- as long as composer can autoload the class.

Where is the model directory?

When we started with Laravel, many developers is confused by the lack of models directory. however, the lack of such a directory is intentional. We find the word “models” ambiguous since it means many different things to many different people. Some developers refer to an application’s “model” as the totality of all of its business logic, while others refer to “models” as classes that interact with a relational database.

For this reason, we choose to place Eloquent models in the app directory by default and allow the developer to place them somewhere else if they choose.

2. The Root Directory.

Here we are going to show root directory in laravel.

The App Directory

The app directory, as you might expect, contain the core code of your application. We will explore this directory in more details soon. However, almost all of the class in your application will be in this directory.

The Bootstrap Directory.

The bootstrap directory contains file that bootstrap the framework and configure autoloading. This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files.

The Config Directory.

The config directory, as the name implies, hold all of your application’s configuration file. It is easy to read through all of these files and familiarize yourself with all of the option available to you.

The Database Directory.

The database directory hold your database migration and seeds. If you want, you may also use this directory to hold an SQLite database.

The Public Directory.

The public directory hold the index.php file, which is the entry point for all requests entering your application. This directory also keep your assets such as images, javascript and CSS.

The Resources Directory.

The resources directory hold your views as well as your raw, un-compiled assets such as LESS, SASS or javascript. This directory also keep all of your language files.

The Routes Directory.

The routes directory hold all of the route definations for your application. By default, several route files are included with Laravel: web.php, api.php, console.php and channels.php.

The web.php file hold routes that the RouteServerProvider places in the web middleware group, which provides session states, CSRF protection and cookie encryption. All of your route will be mostly defined in the web.php file.

The api.php file hold routes that the RouteServerProvider places in the api middleware group, which provide rate limiting.

The console.php a file is where you can define all of your closure based console commands. Each closure is bounded to a command instance allowing a simple approach to interacting with each command’s IO method. This file does not define HTTP routes. Its define console based entry points into your application.

The channel.php file is where you can register all of the event broadcasting channnels that your application supports.

The Storage Directory.

The storage directory hold your compiled blade templates, file based sessions, file caches and other file generated by the framework. The directory is segregated into app, framework and logs directories. The app directory is used to store any files generated by your application. The framework directory is used to store framework generated files and caches. Finally, the logs directory hold your application’s log files.

The storage/app/public directory is used to store user generated files, such as profile avatars, that should be publically accessible. You may create the link using php artisan storage:link command.

The Tests Directory.

The tests directory hold your automated tests. An example PHPUnit is provided out of the box.
Each test class should be suffixed with the word test. You may run your tests using the phpunit or php vender/bin/phpunit commands.

The Vendor Directory.

The vender directory hold your composer dependencies.

3. The App Directory.

The majority of your application is keep in the app directory. By default, this directory is namespaced under App and is autoloaded by composer.

The app directory hold variety of additional directories such as console, Http and providers. Think of the console and Http dirctories as providing an API into the core of your application. The console directory hold all of yourArtisan commands, while the http directory hold your controller, middleware and requests.

The Console Directory

The console directory hold all of the custom artisan commands for your application. these command may be generated using the make:command command. This directory also keep your console kernel, which is where your custom artisan command are registered.

The Events Directory

This directory does not exits by default, but will be created for you by the event:generate and make:event Artisan commands. Event may be used to alert other part of your application that a given action has occurred, providing a great deal of flexibility and decoupling.

The Exceptions Directory

The Exceptions directory hold your application’s exception handler and is also a good place to place any exception thrown by your application. If you would like to customize how your exceptions are logged or rendered, you should modify the handler class in this directory.

The Http Directory

The Http directory hold your controllers, middleware and form requests. Almost all of the logic to handle request entering your application will be placed in this directory.

The Jobs Directory

This directory does not exist by default but will be created for you. if you execute the make:job Artisan command. Jobs may be queued by your application or run synchronously within the current request lifecycle.

The Listeners Directory

The directory does not exist by default, but will be created for you. If you execute the event:generate or make:listener Artisan commands. The listeners directory hold the classes that handle your events.

The Mail Directory

This directory does not exist by default, but will be cretaed for you. If you execute the make:mail
Artisan commands. The mail directory hold all of your classes that represent emails sent by your application.

The Notification Directory

This directory does not exist by default but will be created for you. If you execute the make:notification Artisan command. The notification directory hold all of the transactional notification that are sent by your application. Laravel’s notification features abstract sending notifications over a variety of driver such as email, slacks, sms stored in the database.

The Policies Directory

This directory does not exist by default but will be created for you. If you execute the make:policy Artisan command. The policy directory hold the authorization policy classes for your application. policies are used to determine if a user can perform a given action against a resource.

The Providers Directory

The provider directory hold all of the serviceproviders for your application. Service providers bootstrap your application by binding services in the service container, registering events or performing any other task to prepare your application for incoming requests.

In a fresh Laravel application, this directory will already hold several providers. You are free to add your own providers to this directory as needed.


Advertisements

Add Comment

đź“– Read More