Laravel Folder Structure
Laravel is a PHP framework used to develop web applications. It follows the Model-View-Controller (MVC) architectural pattern and provides developers with a structured and reusable codebase. Laravel offers many built-in features like routing, authentication, session management, and caching, which makes it one of the most popular frameworks for PHP web development.
In this blog, I will explain the folder structure of Laravel.
When you create a new Laravel project, the folder structure looks like this:
├── app ├── bootstrap ├── config ├── database ├── public ├── resources ├── routes ├── storage ├── tests ├── vendor ├── artisan ├── composer.json └── package.json
Here’s an overview of the key folders:
1. app/:
- Contains the core of your Laravel application.
- Subfolders include:
- Console/: Contains artisan commands.
- Http/: Contains controllers, middleware, and form requests.
- Models/: By default, this is where your Eloquent models are located.
- Providers/: Where service providers are registered.
- Exceptions/: Handles exceptions, including custom exception logic.
2. bootstrap/:
- Contains files for bootstrapping the framework.
- The app.php file initializes the Laravel application.
3. config/:
- Contains configuration files for the application. Files like app.php, database.php, and queue.php are found here. These files control various settings for the framework.
4. database/:
- Handles database migrations, factories, and seeds. You will define how the database tables should be structured here.
- Subfolders:
- migrations/: Contains migration files that modify database structure.
- factories/: Allows you to generate test data.
- seeders/: Allows you to seed test data into your database.
5. public/:
- The root directory for web access. It contains the index.php file, which is the entry point for all requests to your Laravel application.
- It also contains assets like CSS, JavaScript, and images.
6. resources/:
- This folder contains your views, raw assets (such as uncompiled CSS or JavaScript), and language files.
- Subfolders:
- views/: Contains Blade templates.
- lang/: Contains language localization files.
- js/, css/: Uncompiled frontend assets (usually for use with build tools like Vite or Mix).
7. routes/:
- Contains route definitions. Laravel organizes routes into different files:
- web.php: Defines routes for web (browser) interactions.
- api.php: Defines routes for API requests.
- console.php: Defines routes for Artisan commands.
- channels.php: Defines channels for broadcasting.
8. storage/:
- Used to store logs, compiled Blade templates, file uploads, and cache data.
9. Subfolders:
- app/: General application storage.
- framework/: Stores framework-generated files.
- logs/: Contains application log files.
10. tests/:
- Contains automated tests for your application. Laravel supports both unit tests and feature tests. By default, Laravel includes some basic example tests.
11. vendor/:
- Contains all the Composer-managed dependencies. Laravel's core codebase and third-party packages are stored here.
12. artisan:
- This is the Artisan command-line interface for Laravel. It provides several helpful commands for development and maintenance, like running migrations, starting a development server, etc.
13. composer.json:
- Manages the PHP dependencies for the project. It defines the packages and libraries your application requires.
14. package.json:
- Manages the Node.js dependencies if you are using Laravel Mix, Vite, or any other front-end build tool.
Laravel's structure is modular and clean, making it easy to scale, maintain, and extend.