CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

30 January, 2024

Dive into the Streamlined Directory Structure in Laravel 11

 Programing Coderfunda     January 30, 2024     No comments   

---



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 in how a typical Laravel application is structured.


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.


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.



The post Dive into the Streamlined Directory Structure in Laravel 11 appeared first on Laravel News.


Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • New Community Project: Laravel Notification Channels Laravel 5.3 will ship with a notification system that includes a Nexmo SMS driver, a Mail driver, and the ability to include cust… Read More
  • Laravel Analytics v2 Freek Van der Herten and Spatie.be recently released a new version of their popular Google Analytics package.Since the first release o… Read More
  • Laravel and Elasticsearch Elasticsearch allows you to search & analyze data in real time. Even though it’s extremely powerful working with delta’s and querying data i… Read More
  • Easily Test Email with MailThief MailThief is a new package by Tighten Co. that provides a fake mailer for your Laravel application. This makes it easy to test em… Read More
  • Easily Integrate HTTP 2 Server Push with a Laravel Middleware As we all know technology changes fast and if you don’t stop and look around once in awhile, you could miss it. HTTP/2 is one area of … Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Spring boot app (error: method getFirst()) failed to run at local machine, but can run on server
    The Spring boot app can run on the online server. Now, we want to replicate the same app at the local machine but the Spring boot jar file f...
  • Log activity in a Laravel app with Spatie/Laravel-Activitylog
      Requirements This package needs PHP 8.1+ and Laravel 9.0 or higher. The latest version of this package needs PHP 8.2+ and Laravel 8 or hig...
  • Laravel auth login with phone or email
          <?php     Laravel auth login with phone or email     <? php     namespace App \ Http \ Controllers \ Auth ;         use ...
  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh
    I had follow these steps to install an configure firebase to my cordova project for cloud messaging. https://medium.com/@felipepucinelli/how...
  • Vue3 :style backgroundImage not working with require
    I'm trying to migrate a Vue 2 project to Vue 3. In Vue 2 I used v-bind style as follow: In Vue 3 this doesn't work... I tried a...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • Transform JSON into Typed Collections with Laravel's AsCollection::of() - 5/18/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda