What's New in Laravel 11
As the heartbeat of modern web development, Laravel continues to captivate developers worldwide with its rich feature set, and unwavering commitment to innovation. With each iteration, the framework not only refines existing functionalities but also introduces groundbreaking features that redefine the standards of web application development.
Application skeleton refinements - No more Http/Kernel
We have got a new file bootstrap/app.php file which is the new entry point for the application. In this file we can define middleware, service providers, exception handling and much more.
Cleaner service providers
Are you familiar with the hassle of juggling numerous service providers? Laravel 11 brings an end to this complexity by introducing a single AppServiceProvider. This enhancement merges the capabilities of existing service providers into either the bootstrap/app.php file or the new AppServiceProvider, streamlining your codebase for improved clarity and efficiency.
PHP 8.2
Laravel 11 will only work on a PHP 8.2 or later. If you are running an older version of PHP, now is a good time to consider upgrading to the latest version and take advantage of the new features and performance improvements that come with it.
Easy Laravel Installation
composer global require laravel/installer
laravel new your-project-name
Introduction of new commands
Laravel 11 introduces a range of new commands that simplify the development process. These include:
php artisan make:class
php artisan make:enum
php artisan make:interface
php artisan make:trait
Eager Loading Limit
Consider you have a Post model with a relationship to Comment model. You can now eagerly load the first 3 comments for each post using the following code:
Post::with([
'comments' => fn ($query) => $query->limit(3)
])->paginate();
To do that in Laravel 10 or earlier, you had to use this library but now this library is included in Laravel 11.
Console Kernel Removed
The Console Kernel is being removed, and you'll be able to instead define your console commands right in routes/console.php.
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
New up Health Route
Laravel 11 includes a new health route that can be used to check the health of your application (/up). This route can be used to check if your application is up and running, and can be used for monitoring purposes.
Refined Routes
By default, Laravel will include only two route files: console.php and web.php. API routes will now be opt-in, accessible via the command php artisan install:api. This command will generate the API routes file.
Per-second rate limiting
Laravel 11 introduces a new per-second rate limiting feature that allows you to limit the number of requests a user can make to your application per second. This feature can be useful for preventing abuse of your application's resources and ensuring that your application remains responsive to legitimate users.
RateLimiter::for('emails', function (Request $request) {
return Limit::perSecond(1);
});
Model::casts() method
Laravel 11 introduces a new Model::casts() method that allows you to define the cast types for model attributes directly on the model class.
class User extends Model
{
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Now you can write it like this:
class User extends Model
{
public function casts(): array
{
return [
'email_verified_at' => 'datetime',
];
}
}
Model::casts() method has higher priority than $casts property.
Laravel Reverb
Laravel 11 comes a first-party WebSocket server tailored for Laravel applications called Laravel Reverb. This server provides a simple and efficient way to handle WebSocket connections in your Laravel applications. For more information on Laravel Reverb, check out the official documentation.
Laravel Context
Laravel's "context" functionalities empower you to capture, retrieve, and distribute information across requests, jobs, and commands within your application. This gathered data is seamlessly integrated into your application's logs, providing comprehensive insight into the code execution history preceding each log entry. This capability facilitates the tracing of execution flows across a distributed system. For more information about Laravel Context, check out the official documentation.
There are many smaller updates here and there. For more details check the release notes of Laravel 11.
SaaSykit is a Laravel 11-based SaaS boilerplate crafted for small teams or solopreneurs seeking to launch their SaaS quickly. It arrives equipped with essential components essential for modern SaaS operations: customizable branding, themes, integration with leading payment providers (Stripe, Paddle, and Lemon Squeezy), support for subscription and one-time purchase products, discount capabilities, a pre-built blog, an elegant admin panel, customer dashboard, social login options via Google, Facebook, X, and an array of additional features.
Discover how SaaSykit streamlines SaaS development, saving you valuable time and effort.