Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Laravel 12.x Application Structure

    Laravel 12.x Tutorials


    Before you start coding in Laravel, it's important to understand how a Laravel project is organized. Laravel 12.x follows a structured folder layout that keeps code clean and manageable. Each directory in a Laravel application has a specific purpose, from routing and controllers to views and configuration files. This tutorial explains the Laravel 12.x application structure and the role of each key folder.

    Why Understanding Structure Matters

    Understanding the Laravel 12.x folder structure helps you know where to place your code and how Laravel loads and organizes everything. Each folder has a clear role, from routes and controllers to views and configuration. Knowing this structure early on will help you work more efficiently and build applications that are easier to maintain.

    Root Directory Overview

    When you create a Laravel project, you'll see several folders and files in the root directory.

    laravel_test/
    ├── app/
    │   ├── Console/
    │   ├── Exceptions/
    │   ├── Http/
    │   │   ├── Controllers/
    │   │   ├── Middleware/
    │   ├── Models/
    │   ├── Providers/
    ├── bootstrap/
    │   └── cache/
    │   └── app.php
    ├── config/
    ├── database/
    │   ├── factories/
    │   ├── migrations/
    │   ├── seeders/
    │   └── .gitignore
    ├── public/
    ├── resources/
    │   ├── css/
    │   ├── js/
    │   └── views/
    ├── routes/
    │   ├── api.php
    │   ├── channels.php
    │   ├── console.php
    │   └── web.php
    ├── storage/
    │   ├── app/
    │   ├── framework/
    │   └── logs/
    │   └── .gitignore
    ├── tests/
    │   ├── Feature/
    │   │   └── CreatesApplication.php
    │   ├── Unit/
    │   │   └── TestCase.php
    ├── vendor/
    ├── .editorconfig
    ├── .env
    ├── .env.example
    ├── .gitattributes
    ├── .gitignore
    ├── artisan
    ├── composer.json
    └── package.json
    

    Note: This matches a standard Laravel 12.x project after composer install is run. All necessary core folders and supporting files are in place.

    Key Laravel Directories

    Here are the key directories in a Laravel 12.x project:

    app/ – Application Code

    This is where most of your application logic lives. It includes:

    • Console/ – Defines custom Artisan commands.
    • Exceptions/ – Handles custom error reporting and exception rendering.
    • Http/ – Contains controllers, middleware, and form requests used to handle HTTP requests.
    • Models/ – Stores your Eloquent models that work with the database.
    • Providers/ – Registers services and bootstraps application functionality during startup.
      You can also create custom folders here to organize your code further, like Services/, Helpers/, or Events/.

    bootstrap/ – Framework Bootstrapping

    Contains files that initialize the framework. The app.php file sets up the application instance. The cache/ folder stores optimized files for configuration and route loading.

    config/ – Application Configuration

    This folder contains all configuration files for the framework and various services. Files like app.php, database.php, and mail.php define how different parts of the application behave. You can access these settings using the config() helper function.

    database/ – Migrations, Seeders, Factories

    Manages your database schema and test data.

    • migrations/ – Define version-controlled changes to your database structure.
    • seeders/ – Populate tables with sample or default data.
    • factories/ – Define templates for generating fake data for testing.

    public/ – Web Entry Point

    This is the root directory exposed to the browser. It contains the index.php file, which is the entry point for all HTTP requests. You can also place public assets like images, CSS, and JavaScript here.

    resources/ – Views and Frontend Assets

    Contains frontend-related files:

    • views/ – Blade templates used to generate HTML pages.
    • css/, js/ – Frontend assets used in your application.
    • lang/ – (If present) Custom language files for localization.

    routes/ – Application Routes

    Defines all the routes that Laravel responds to:

    • web.php – Routes using web middleware (sessions, CSRF protection).
    • api.php – Stateless routes for APIs.
    • console.php – Defines Artisan commands.
    • channels.php – Used for broadcasting events over WebSockets.

    storage/ – Application Storage

    Used for runtime files and logs.

    • app/ – Stores user-generated files.
    • framework/ – Contains compiled Blade templates, session data, and cached files.
    • logs/ – Stores application log files.
      Make sure this folder is writable by the server.

    tests/ – Application Testing

    This directory is used for automated testing using PHPUnit.

    • Feature/ – Tests that check complete features or flows.
    • Unit/ – Tests individual classes or methods.
      Includes default setup files like TestCase.php and CreatesApplication.php.

    vendor/ – Composer Dependencies

    Created after running composer install. This folder contains all third-party PHP packages and the Laravel framework core files. It should not be edited manually.


    Supporting Files

    Here are the key supporting files in a Laravel 12.x project:

    .env

    Holds environment-specific settings such as database credentials, mail configurations, app name, and debug mode. Laravel uses this file to load configuration values at runtime.

    .env.example

    A sample version of the .env file. It's useful for sharing environment structure with teammates without exposing sensitive data.

    artisan

    Laravel's command-line tool used to run framework-specific commands. You can use it for generating files, running migrations, clearing caches, starting the local server, and more.

    composer.json

    Defines PHP dependencies and scripts. It's used by Composer to install and autoload Laravel and other packages.

    package.json

    Lists Node.js packages and scripts used for frontend asset management. Tools like Vite or Laravel Mix use this file for building and bundling frontend code.

    .gitignore

    Specifies which files and folders Git should ignore, such as vendor/, node_modules/, and compiled assets.

    .editorconfig, .gitattributes

    Optional files to enforce coding standards across development tools and improve Git behavior on different platforms.

    Conclusion

    In this tutorial, you learned how a Laravel 12.x project is structured and what each main directory and file is used for. Understanding the folder layout helps you place your code correctly, follow best practices, and manage your project more efficiently as it grows.



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.