Directory Structure
Introduction
The default Laravel application structure is intended to provide a great starting point for both large and small applications. But 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 Models Directory?
When getting started with Laravel, many developers are confused by the lack of a 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.
The Root Directory
The App Directory
The app
directory contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.
The Bootstrap Directory
The bootstrap
directory contains the app.php
file which bootstraps the framework. 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, contains all of your application's configuration files. It's a great idea to read through all of these files and familiarize yourself with all of the options available to you.
The Database Directory
The database
directory contains your database migrations, model factories, and seeds. If you wish, you may also use this directory to hold an SQLite database.
The Public Directory
The public
directory contains the index.php
file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.
The Resources Directory
The resources
directory contains your views as well as your raw, un-compiled assets such as LESS, SASS, or JavaScript. This directory also houses all of your language files.
The Routes Directory
The routes
directory contains all of the route definitions 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 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 offer a stateless, RESTful API, all of your routes will most likely be defined in the web.php
file.
The api.php
file contains routes that the RouteServiceProvider
places in the api
middleware group, which provides rate limiting. These routes are intended to be stateless, so requests entering the application through these routes are intended to be authenticated via tokens and will not have access to session state.
The console.php
file is where you may define all of your Closure based console commands. Each Closure is bound to a command instance allowing a simple approach to interacting with each command's IO methods. Even though this file does not define HTTP routes, it defines console based entry points (routes) into your application.
The channels.php
file is where you may register all of the event broadcasting channels that your application supports.