🧭 Navigating the Laravel 12 Project Structure

🧭 Navigating the Laravel 12 Project Structure

Laravel 12 features a clean and well-structured directory structure that aids in maintainability and scalability. Below is a description of the primary directories:

1. app/ – Core Application Code

This is the brain of your application. It, by default, includes:

  • Http/: Contains controllers, middlewares, and form request classes.
  • Models/: Stores Eloquent models for your database tables.
  • Providers/: Contains service providers for bootstrapping the application’s services.

Other folders like Console/, Events/, Jobs/ can also be created, still in the course of generating specific classes with the command tools of Artisan

2. bootstrap/ – Application Bootstrapping

  • This directory contains the app.php file, from which the framework gets bootstrapped.
  • The cache/ subdirectory is useful for storing files the framework might generate for performance optimization.

3. config/ – Configuration Files

It is where all the configuration files are situated for the application e.g., app.php, database.php, and mail.php. Each file gives you the freedom to adjust different parts of the framework's functioning.

4. database/ – Database Migrations and Seeders

Includes:

  • migrations/: Defines the database schema.
  • seeders/: They are used to put random, but real-looking data in the database.
  • factories/: This generates fake data for testing

5. public/ – Files Located Publicly

The access point for each of the requests that are coming into the application (index.php). This folder is also used to hold other files such as pictures, JavaScript, and CSS. Files and folders from this directory are easily accessible by anyone.

6. resources/ – Views and Assets

Consists of this:

  • views/: Present the frontend of the application through Blade templates.
  • lang/: Files with translations for the various languages that the application supports.
  • css/ and js/: Uncompiled CSS and JavaScript assets

7. routes/ – Route Definitions

Identify the routes for the application:

  • web.php: It contains the initial routes for the web interfaces.
  • api.php: Behind the scenes, these routes are HTTP API routes (the case when php artisan install:api is executed).
  • console.php: They are closure-based commands for the console (that's the method to execute for replacing the traditional Console/Kernel.php
  • channels.php: Event broadcasting channels.

8. storage/ – Compiled Templates and Logs

It is where the server keeps caches, application logs, file sessions, and Blade templates that have been compiled. And this directory is writable by the web server.

9. tests/ – Automated Tests

It contains:

Ensure unit and feature tests of the application to check that it behaves as expected. Laravel 12 supports both PHPUnit and Pest testing frameworks.

10. vendor/ – Composer Dependencies

It contains all the composer-managed packages and dependencies. In the usual case, you don't have to change anything here.

🆕 Notable Changes in Laravel 12

  • Deferred Directory Creation: The directories, such as Console/, Events/, Jobs/, etc., are created when corresponding classes are generated using Artisan commands. This way of doing things maintains the basic project structure,e clean and simple.
  • Simplified Kernel Files: The classic Http/Kernel.php and Console/Kernel.php files are no longer available. Instead, routers and console commands are placed directly in the routes/ directory.
  • Optional API and Broadcasting Routes: Try to remember that api.php and channels.php are not generated by default. They are created with you can run the php artisan install:api and php artisan install: broadcasting commands one by one.


To view or add a comment, sign in

More articles by Bilawal B.

Insights from the community

Others also viewed

Explore topics