NashTech Blog

Unveiling Laravel 11: The Future of PHP Development

Table of Contents
black and white laptop computer on brown wooden desk

Laravel 11 is here, revolutionizing the PHP development landscape. Firstly, it requires PHP 8.2 as the minimum version, thereby leveraging the newest language features to boost performance and security. Moreover, in this new version, Laravel introduces a slim skeleton structure, also known as Streamlined Application Structure, which makes it leaner and more efficient. Consequently, let’s say goodbye to cluttered folders; the new structure is optional for existing projects but default for new ones.

For testing aficionados, Laravel 11 changes the default to Pest, an elegant PHP testing framework, and SQLite for databases. This shift towards modern defaults signifies Laravel’s commitment to staying at the forefront of development trends.

Pest – PHP testing framework

The New Structure

Streamlined Application Structure

The new minimalistic application structure simplifies the folder layout for new projects without requiring changes for existing applications.

Streamlined Application Structure

Laravel 11 has removed certain config files (broadcasting.phpcors.phphashing.phpsanctum.phpview.php) to streamline the configuration. However, these can be manually published if needed. Ideal for microservices and smaller web applications, this feature allows developers to create lightweight projects without unnecessary components, leading to faster deployment and easier maintenance. 

The streamlined application structure revitalizes:

  • Enhanced Application Bootstrap 
  • Single Service Provider
  • API and Broadcast Routing 
  • Exception Handling 
  • Base Controller Class
  • Scheduling Facade

Enhanced Application Bootstrap

The bootstrap/app.php  file has been upgraded as a code-first application configuration file. So that, it can unify a variety of high-level application behavior settings that were previously scattered throughout your application’s file structure. From this file, you may now customize your application’s routing, middleware, service providers, exception handling, and more.

Previous bootstrap file
Laravel 11 bootstrap file

Single App Service Provider

Instead of the default Laravel application structure containing five service providers, Laravel 11 only includes a single AppServiceProvider class. The framework now incorporates the functionalities of service providers into the bootstrap/app.php, and manages them automatically.

For example, Laravel now enables the event discovery by default, eliminating the need for manual registration of events and their listeners. However, if you do need to manually register events, you may simply do so in the AppServiceProvider class. Similarly, with the route model bindings or authorization gates, you have previously registered in the AuthServiceProvider. Now, you can register them in the AppServiceProvider class.

Previous Providers Structure
New Providers Structure
Previous Service Provider Registration
New Service Provider Registration

API and Broadcast Routing

One of the most notable changes is the optional installation of API and broadcasting features. Laravel 11 has removed the routes/api.php file and the Sanctum package from the default installation, allowing you to install them using simple Artisan commands only when needed.

This change is particularly useful for projects that do not require API or real-time capabilities. It helps reduce package complexity and improve application overall performance.

Api and Broadcasting commands

Exception Handling

Similar to routing and middleware, you can now customize exception handling from your application’s bootstrap/app.php file instead of using a separate exception handler class, reducing the overall number of files in a new Laravel application.

Old Exception Folder
Exception Folder Removed in Laravel 11
New Exception Handler Definition

Base Controller Class

The base controller now contains in new simplified abstract structure. It no longer extends Laravel’s internal Controller class. The AuthorizesRequests and ValidatesRequests traits were removed. We can include these traits in our desired individual controller classes.

Previous Version Base Controller
Laravel 11 Base Controller

New Scheduling Facade

With a new Schedule facade, we now can directly define scheduled tasks in the application’s routes/console.php file, which eliminates the need for a separate console “kernel” class. 

Previous Version Console Structure
Laravel 11 Console Structure
New Schedule Facade Usage

Updated default packages and drivers

Pest, serving as the default testing framework based on PHPUnit, brings exciting features that you might find appealing. It offers a user-friendly API influenced by Ruby’s Rspec and Jest libraries, making it simple to write elegant tests quickly. The visually impressive console output makes it easy to identify issues. Moreover, the Pest framework includes built-in parallel testing, code coverage, watch mode, architecture testing, native profiling tools, snapshot testing, and exceptional documentation.

Laravel 11 Sample Test

SQLite is the default database storage in Laravel 11 as well as the default database driver for Laravel’s session management, caching, and queue. This configuration underscores Laravel’s dedication to modern development practices. Developers can begin building applications right away after creating a new Laravel project, without the need for additional software installation or extra database migrations.

This streamlined setup offers a practical and consistent choice for both local and development environments, simplifying the testing process for developers, making it more accessible and efficient, especially for continuous integration environments.

Default PHPUnit Configuration in Laravel 11

Conclusion

Laravel 11 brings a suite of powerful new features designed to enhance developer productivity and streamline application development. The Streamlined Application Structure simplifies folder layouts, while the Enhanced Application Bootstrap reduces file clutter. Finally, the new updated Scheduling Facade also further enhance the development experience. In Overall, these advancements make Laravel 11 a robust and efficient framework for modern PHP development.

Reference

Picture of Khoi Quan

Khoi Quan

I love to build a product, especially a good one. But what does a good product look like? In my aspect, it needs to improve user’s productivity and save their time or give new experiences that they have never had before. It is so fantastic that I am able to keep doing what I love in my daily work at Nash Tech Company. As a technical architect of the team, I take the responsibility for delivering high quality products. It is also my fun puzzle to always think of the most ways that I could make a product more stable and flexible to adapt with new changes or apply new technologies that could improve the performance or bring out more value to client.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top