# Laravel Directory Structure
This document comes from Laravel official. Generally, you don't need to pay too much attention to it. It is recommended to check it directly BeikeShop Directory Structure
# Introduction
The default Laravel application structure is designed to provide a great starting point for both large and small applications. However, you are free to organize your application however you like. Laravel places almost no restrictions on the location of any given class, as long as Composer can autoload that class.
# Root Directory
# App Directory
The app
directory contains the core code for your application. We will explore this directory in more detail shortly; however, almost all of the classes in your application will be in this directory.
# Bootstrap Directory
The bootstrap
directory contains the app.php
file that boots the framework. This directory also contains a "cache" directory that contains framework-generated files for performance optimization, such as routing and service cache files. You typically do not need to modify any files in this directory.
# Config Directory
As the name suggests, the config
directory contains all the configuration files for your application. It is a good idea to go through all of these files and familiarize yourself with all the available options.
# Database Directory
The database
directory contains database migrations, model factories, and seed generator files. If you wish, you can also use it as a SQLite database storage directory.
# Lang Directory
The lang
directory contains all the language files for your application.
# Public Directory
The public
directory contains the index.php
file, which is the entry point for all requests into your application and configures autoloading. This directory also contains your assets, such as images, JavaScript scripts, and CSS styles.
# Resources Directory
The resources
directory contains views and uncompiled resource files (such as CSS or JavaScript). This directory also contains all language files.
# Routes Directory
The routes
directory contains all the route definitions for your application. By default, Laravel includes several route files: web.php
, api.php
, console.php
, and channels.php
.
The web.php
file contains routes that the RouteServiceProvider
places in the web
middleware group, which provides session state, CSRF protection, and cookie encryption. If your application does not provide a stateless RESTful API, then all of your routes will most likely be in the web.php
file.
The api.php file contains routes that the RouteServiceProvider places in the api middleware group. These routes are intended to be stateless, so requests coming into the application through these routes are intended to be authenticated via tokens and have no access to session state.
The console.php
file is where you can define all of your Closure-based console commands. Each Closure is bound to a command instance, allowing an easy way to interact with each command's IO methods. Even though this file does not define HTTP routes, it defines the console-based entry points (routes) in your application.
The channels.php
file is where you can register all of the event broadcasting channels that your application supports.
# Storage Directory
The storage
directory contains your logs, compiled Blade templates, file-based sessions, file caches, and other files generated by the framework. This directory is divided into app
, framework
, and logs
directories. The app
directory can be 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 contains your application's log files.
The storage/app/public
directory can be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link to this directory in public/storage
. You may create a link using the php artisan storage:link
Artisan command.
# Tests Directory
The tests
directory contains your automated tests. Example PHPUnit (opens new window) unit tests and functional tests are provided out of the box. Each test class should be suffixed with the word "Test". You can run your tests using the phpunit
or php vendor/bin/phpunit
commands. Alternatively, if you want a more detailed and prettier presentation of test results, you can run your tests using the php artisan test
Artisan command.
# Vendor Directory
The vendor
directory contains your Composer (opens new window) dependencies.
# App Catalog
The bulk of your application will be located in the app
directory. By default, this directory is named under App
and is autoloaded by Composer using the PSR-4 autoloading standard (opens new window).
The app
directory contains various additional directories, such as Console
, Http
, and Providers
. Think of the Console
and Http
directories as providing an API for the core of your application. The HTTP protocol and the CLI are both mechanisms for interacting with your application, but do not actually contain your application logic. In other words, they are two ways of issuing commands to your application. The Console
directory contains all of your Artisan commands, while the Http
directory contains your controllers, middleware, and requests.
When you generate classes using the make
Artisan command, various other directories are generated within the app
directory. So, for example, the app/Jobs
directory will not exist until you execute the make:job
Artisan command to generate your job classes.
Tip: Many of the classes in the
app
directory can be generated by Artisan commands. To view the available commands, run thephp artisan list make
command in your terminal.
# Broadcasting Directory
The Broadcasting
directory contains all of your application's broadcast channel classes. These classes are generated using the make:channel
command. This directory does not exist by default, but will be created for you when you create your first channel. To learn more about channels, check out the documentation on event broadcasting.
# Console Directory
The Console
directory contains all of your application's custom Artisan commands. These commands may be generated using the make:command
command. This directory also contains your console kernel, which is where you register custom Artisan commands and define scheduled tasks.
# Events Directory
This directory does not exist by default, but will be created for you by the event:generate
and make:event
Artisan commands. The Events
directory contains Event classes. Events can be used to alert other parts of your application that a given action has occurred, allowing for a great deal of flexibility and decoupling.
# Exceptions Directory
The Exceptions
directory contains your application's exception handlers, and is also a good place to put any exceptions that your application throws. If you want to customize the way exceptions are logged or presented, you should modify the Handler
classes in this directory.
# Http Directory
The Http
directory contains your controllers, middleware, and form requests. Almost all of the logic for handling requests coming into your application will be placed in this directory.
# Jobs Directory
This directory does not exist by default, but will be created for you if you execute the make:job
Artisan command. The jobs
directory contains your application's queue jobs. Jobs may be queued by your application or run synchronously during the current request lifecycle. Jobs that run synchronously during the current request are sometimes referred to as "commands" because they are an implementation of the Command pattern (opens new window).
# Listeners Directory
This 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 contains classes that handle your events. Event listeners receive event instances and perform logic in response to the event being fired. For example, the UserRegistered
event might be handled by a SendWelcomeEmail
listener.
# Mail Directory
This directory does not exist by default, but will be created for you if you execute the make:mail
Artisan command. The Mail
directory contains all of the classes that represent email messages sent by your application. The Mail object allows you to encapsulate all of the logic for building an email in a simple class that can be sent using the Mail::send
method.
# Models Directory
The Models
directory contains all of the Eloquent model classes. The Eloquent ORM included with Laravel provides a nice, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "model" that is used to interact with that table. Models allow you to query data in a table, as well as insert new records into a table.
# Notifications Directory
This directory does not exist by default, but is automatically created if you execute the make:notification
Artisan command. The Notifications
directory contains all of the "transactional" message notifications that you send to your application. For example, simple notifications about events that occur within your application. Laravel's notification functionality abstracts notifications sent through a variety of drivers, such as email notifications, Slack messages, SMS text messages, or database storage.
# Policies Directory
By default, this directory does not exist, but will be generated if you execute the make:policy
Artisan command. The Policies
directory contains your application's authorization policy classes . These classes are used to determine whether a user can perform a given action on a resource.
# Providers Directory
The Providers
directory contains all of the service providers for your application. Service providers bootstrap your application in response to incoming requests by binding services in the service container, registering events, or performing any other task.
In a new Laravel application, this directory already contains several providers. You can add your own providers to this directory as needed.
# Rules Directory
By default, this directory does not exist, but will be created if you execute the make:rule
Artisan command. The Rules
directory contains custom validation rules that may be defined by the users of your application. These validation rules are used to encapsulate complex validation logic in a simple object. For more information, see Form Validation.