1. Introduction
Laravel applying the default directory structure attempts to provide a good starting point for both large and small applications, and of course, you can reorganize the application directory structure yourself as you like, laravel there are no restrictions on where classes are loaded-as long as composer can load them automatically.
2. root directory
The newly installed Laravel app contains many folders:
app
The directory contains the core code of the application;
bootstrap
The directory contains a few files for the framework's startup and automatic loading configuration, and a cache
folder to contain the boot files generated by the framework to improve performance;
config
The directory contains all the configuration files for the application;
database
The directory contains data migration and fill files, if you like it can also be used as a SQLite database storage directory;
public
The directory contains the front-end controller and resource files (Pictures, JS, CSS, etc.);
resources
The directory contains view files and native resource files (less, SASS, Coffeescript), and localized files;
storage
The directory contains the compiled blade template, the file-based session, the file cache, and other framework-generated files, which are quarantined into app
, framework
and logs
directories, app
directories used to store the files that framework
the application will use. The directory is used to hold the files and caches generated by the framework, and finally, the logs
directory contains the application log files;
tests
The catalog contains automated tests, which already provide an out-of-the-box PHPUnit example;
vendor
The directory contains composer dependencies;
3. App Directory
The core code of the app is located in the app
directory, which, by default, is located under the Namespace app and is automatically loaded by composer via PSR-4 auto load standard. You can app:name
modify the namespace with the artisan command.
app
The directory contains multiple subdirectories, such as Console
,, Http
, and Providers
so on. Console
and Http
directories provide access to the application core of the Api,http protocol and the CLI are two mechanisms for interacting with the application, but do not actually contain the application logic. In other words, they are just two ways to publish commands to an app. The Console
directory contains all the artisan commands, including Http
controllers, filters, requests, and so on.
Jobs
A directory is where a queue task is placed, the tasks in the app can be queued, or they can be executed synchronously during the current request life cycle.
Events
The directory is where the event classes are placed, and events can be used to inform the application that other parts of the given action have occurred and provide flexible decoupling processing.
Listeners
The directory contains the processor class for the event, the processor receives an event and provides the response logic after the event, for example, the UserRegistered
event can be handled by the SendWelcomeEmail
listener.
Exceptions
The directory contains the exception handler for the application, and it is a good place to handle any exceptions thrown by the app.
Note: app
Many of the classes in the directory can be generated through the artisan command, and to see all valid commands, you can run the commands in the terminal php artisan list make
.
4. Set the application's command space
As discussed above, applying the default namespace is, App
of course, you can modify the namespace to match the name of the app, and modifying the namespace can be done by app:name
command. For example, if your app is named "Socialnet", you can run the following command:
php artisan app:name SocialNet
Of course, you can also continue to use App
namespaces without modification.
[Laravel 5.1 Document] schema--Application directory structure