Dive into the Streamlined Directory Structure in Laravel 11

Last updated on by

We think you’ll love the fresh skeleton you start with in a Laravel 11 app that is coming out next week! Newcomers will appreciate the minimalism, and experienced developers upgrading will not experience breaking changes. You don't have to change your Laravel 10 application structure to upgrade to Laravel 11.

If you want to follow along and experiment, you can create a Laravel 10 and Laravel 11 project side by side. We used the following commands to do so:

# Update the installer
composer global update laravel/installer -W
 
cd path/to/projects
 
# Create a Laravel 10 app
laravel new laravel-10-app -n --git --pest
 
# Crate a Laravel 11 app
laravel new laravel-11-app --dev -n --git --pest

On the surface, the project directory structure looks identical:

However, if you start diving into the subdirectories, the file count has dropped from a fresh Laravel 11 installation by ~ 69 files:

# Fresh Laravel v10 app
$ find . -type f -not -path "./vendor/*" | wc -l
=> 217
 
# Fresh Laravel v11 app (as of 01/29/2024)
$ find . -type f -not -path "./vendor/*" | wc -l
=> 148

Let's review the most significant updates and see how they compare to a Laravel 10 application so you can be ready for the changes coming to fresh Laravel 11 apps.

The app Directory

The app directory has been slimmed down tremendously, moving the nine middleware that ships with Laravel into the framework and out of the project. Typically, these middleware are not heavily customized, and Laravel 11 will provide other methods to customize built-in middleware and add your own middleware.

The app directory in a fresh Laravel 11 app

Middleware changes are done through the bootstrap/app.php file, which is, according to Taylor Otwell, a “lean routes-esque style file for configuring Laravel” that looks like the following:

return Application::configure(basePath: dirname(__DIR__))
->withProviders()
->withRouting(
web: __DIR__.'/../routes/web.php',
// api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
// channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();

You could add an application middleware by adding something like the following in the withMiddeware() closure:

$middleware->web(append: \App\Http\Middleware\ExampleMiddleware::class);

The Kernel.php files are no longer in the Laravel project, and these are handled through the framework bootstrap/app.php file.

You might have also noticed that the Controllers directory only includes one Controller class that doesn’t extend from anything. It’s up to you how you’d like to extend your controllers (or not), but it provides a default abstract Controller class.

The config Directory

The biggest shock for you might be the updated config directory, which has…nothing inside of it (other than the .gitkeep file). You will, however, notice that many more configuration options exist in the .env.example file.

If you want to publish any given configuration file from the framework to customize it, you can do so via the config:publish command:

# config/database.php
php artisan config:publish database
 
# config/logging.php
php artisan config:publish logging
 
# Or publish all of them
php artisan config:publish

You are free to only extend the configuration values you care about, and they will be merged with the framework’s defaults so you don’t have to keep all published configuration options in a given file.

Suppose you want to look up configuration values in the framework-shipped configuration. In that case, you can use the Artisan config:showcommand, publish the config, or look it up in the config/logging.php file within the Laravel vendor folder:

php artisan config:show logging
 
cat vendor/laravel/framework/config/logging.php

The database Directory

The database directory is roughly the same. However, you’ll notice that the migration filenames are prefixed in a way that does not represent a given date but keeps them in order as needed. The create_personal_access_tokens.php migration file is no longer in the project. Personal access tokens are only required if you build an API, which we will cover in the routes directory changes.

Also, the database.sqlite file will be installed by default unless you pick a different database option when creating a new Laravel project.

The routes Directory

The routes directory was also slimmed down only to include the web.php and the console.php routes files. If you want to create an API or use the broadcasting functionality, you can install them via artisan:

php artisan install:api
php artisan install:broadcasting

Those commands will bring in the required migrations, JavaScript, and configuration files. What’s nice about this is that applications that don’t need broadcasting or API routes don’t have to worry about these unnecessary files being in the project.

Laravel 11 routes directory

The test Directory

The test/ directory no longer includes the CreatesApplication trait in Laravel 11 projects. If you upgrade your Laravel 10 project, you can remove this trait, as it’s now provided as part of the base TestCase from the framework.

In a Laravel 10 project, the only thing included in the base TestCase class in Laravel 10 is the CreatesApplication trait, which bootstraps the application when creating a fresh application as part of the setup before each test. You can safely remove this trait (and its usage) once you upgrade existing apps to Laravel 11.

From Laravel 10 to Laravel 11

You don't have to change your Laravel 10 application's structure at all to upgrade to Laravel 11. This will only be the structure for brand new applications and you'll still be able to use the old way if you prefer.

Learn More

If you want to learn more about Laravel 11, check out our Laravel 11 post with all the details on this exciting new release.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Tinkerwell

Version 4 of Tinkerwell is available now. Get the most popular PHP scratchpad with all its new features and simplify your development workflow today.

Visit Tinkerwell
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with Vue and Livewire stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Configuring Laravel With Additional Environment Files image

Configuring Laravel With Additional Environment Files

Read article
Real Time Command Line Monitoring With Laravel Top image

Real Time Command Line Monitoring With Laravel Top

Read article
A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8 image

A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8

Read article
New Proposed Array Find Functions in PHP 8.4 image

New Proposed Array Find Functions in PHP 8.4

Read article
Laracon AU 2024 tickets are now on sale image

Laracon AU 2024 tickets are now on sale

Read article
Dash UI is a Laravel Blade Component Library Inspired by Shopify Polaris image

Dash UI is a Laravel Blade Component Library Inspired by Shopify Polaris

Read article