/

August 6, 2024

Latest Features and Updates in Laravel 11

Laravel 11 introduces cutting-edge features and updates, enhancing developer productivity and application performance. With advancements in areas like real-time collaboration, serverless computing integration, and improved developer tooling, Laravel continues to lead the way in modern PHP development.

1. PHP Requirement:

  • Minimum Requirement PHP :- 8.2

2. Folder Structure:

  • App Folder:- 

    Removed Folders:
    app/Console: Console commands are now registered in bootstrap/app.php. You can still generate console commands using Artisan. app/Exceptions: Exception handling logic is now configured in bootstrap/app.php. app/Http/Middleware: Default middleware classes are removed. Middleware is now registered in bootstrap/app.php, allowing for more flexibility.

  • Bootstrap Folder:-
  
  1. New bootstrap/app.php file:  This file acts as the central point for registering essential application components. It now handles:
  2. Route registration: Previously done in separate route files, you now register routes (API, web, etc.) directly in this file.
  3. Middleware registration: Instead of default middleware classes, you explicitly define the middleware you want to use in your application here.
  4. Exception handling: Logic for handling exceptions is now configured in this file.

3. Config Folder:

Laravel 11 introduced significant changes to the config folder, promoting a more minimalistic and flexible approach to configuration management. Here’s a breakdown of the key changes:

1.config/broadcasting.php

2.config/cors.php

3.config/hashing.php

4.config/sanctum.php

5.config/view.php

4. Routes Folder :-

  • Removed Route Files (By Default): 

    Unlike Laravel 10 where you typically had separate files for web and API routes (e.g., routes/web.php and routes/api.php), Laravel 11 removes these files by default.

    If can use api and Channels routes in routes folder run this command:-

php artisan install:api
php artisan install: broadcasting

5. .env Folder :-

By Default Database: –

In Laravel 11, SQLite is provided as the default database compared to Laravel 10 where MySQL was the default.

To switch to a MySQL database, update the .env file as follows:

 

6. Laravel Reverb: –

  1. Laravel Reverb is a WebSocket server written specifically in PHP. It integrates seamlessly with Laravel’s existing broadcasting features (like Laravel Echo) to enable real-time data exchange between your application’s server and client-side components (JavaScript).Installation: Include the laravel/reverb package in your project’s composer.json file and run composer update to install it.

    Configuration: Configure Reverb in your config/reverb.php file, specifying details like server address and port.

7. Once Method :-

  1. The once method takes a closure (anonymous function) as an argument.
  2. The first time the once method is called with a specific set of arguments, it executes the provided closure and stores the result.
  3. On subsequent calls with the same arguments, the once method returns the cached result without re-running the closure.
 

8. New Artisan Command :-

php artisan make:class
php artisan make:enum
php artisan make:interface
php artisan make:trait

9. Per-Second Rate Limit:-

In Laravel 11, the RateLimiter facade provides a powerful tool for implementing rate limiting in your application. While historically it could only limit requests by the minute, Laravel 11 introduces support for per-second rate limiting. This allows you to define more granular control over the number of requests a user or process can make within a single second.

Example:-

 

7. Name Argument Removed:-

  • Laravel 11, several functions within Laravel might have accepted a name argument as an optional parameter. This argument often served the purpose of providing a human-readable name or identifier for the action being performed.     In Laravel 11, the name argument has been removed from some of these functions, including:

    dispatch method of the Queue facade.

    assertDispatched method of the TestCase class for testing queued jobs.

  • How to Use the tools now :- 

    Dispatching Jobs: 

    Instead of: dispatch(‘MyJob’, [‘data’ => $data], ‘Process Order’) 

    Now: dispatch(MyJob::class, [‘data’ => $data])
    Testing jobs:

     

    Instead of: assertDispatched(MyJob::class, ‘Process Order’) 

    Now: assertDispatched(MyJob:class) 


From the same category