Understanding the Directory Structure of Laravel 10
When you start a new Laravel project, one of the first things you'll notice is its well-organized directory structure. Understanding how this structure works is crucial for navigating and developing your application efficiently. In this post, we'll break down the main directories and files in a typical Laravel 10 project, so you know where to find everything you need.
The Root Directory
When you create a new Laravel application, you’ll see a variety of folders and files in the root directory. Here’s a quick overview of some of the key components:
-
app/
: This directory is where your application logic lives. It contains all the core code for your application, including controllers, models, and services. You’ll spend a lot of time here as you develop your app. -
bootstrap/
: This folder contains files necessary for bootstrapping your application, including theapp.php
file, which sets up the framework and loads your application. -
config/
: All your configuration files are stored here. This includes database settings, mail settings, caching, and more. Each file corresponds to a specific part of your application. -
database/
: This directory is where you manage your database migrations, model factories, and seeders. Migrations help you define and manage your database schema, while seeders allow you to populate your database with sample data. -
public/
: This is the public-facing directory of your application. It contains theindex.php
file, which is the entry point for all web requests. Any assets like images, CSS, and JavaScript files that need to be accessible from the web should go in this folder. -
resources/
: Here’s where you’ll find your views (HTML templates), language files, and raw assets (like SASS or JavaScript). Theviews/
folder is where your Blade templates are stored, and you’ll be modifying these as you build your app. -
routes/
: This folder contains the route definitions for your application. Laravel uses a routing system to map URLs to specific actions in your application. You’ll find files likeweb.php
andapi.php
here, where you can define routes for web and API requests. -
storage/
: This directory is used to store logs, compiled Blade templates, file uploads, and other files that your application generates. It’s split into several subdirectories, includingapp/
,framework/
, andlogs/
. -
tests/
: This is where your test files reside. Laravel encourages testing your application, and this directory contains unit and feature tests to ensure your application behaves as expected. -
vendor/
: This directory is created when you run Composer. It contains all the dependencies your application uses, including Laravel itself and any third-party packages.
Example Directory Structure
To give you a clearer picture, here’s how the directory structure of a typical Laravel 10 application looks:
my-laravel-app/
├── app/
│ ├── Console/
│ ├── Exceptions/
│ ├── Http/
│ ├── Models/
│ └── Providers/
├── bootstrap/
│ └── cache/
├── config/
├── database/
│ ├── factories/
│ ├── migrations/
│ └── seeders/
├── public/
│ ├── css/
│ ├── js/
│ └── index.php
├── resources/
│ ├── lang/
│ └── views/
├── routes/
│ ├── api.php
│ └── web.php
├── storage/
│ ├── app/
│ ├── framework/
│ └── logs/
├── tests/
│ ├── Feature/
│ └── Unit/
└── vendor/
Conclusion
Understanding the directory structure of Laravel 10 is essential for effective development. With this knowledge, you can quickly navigate your project, find the files you need, and organize your code in a way that makes sense.