Laravel Idea for PhpStorm - Full-featured IDE for productive artisans!

Chaperone, Defer, Cache::flexible, and more are now available in Laravel 11.23

Published on by

Chaperone, Defer, Cache::flexible, and more are now available in Laravel 11.23 image

The Laravel team released v11.23 this week, with the Laracon US 2024 open-source updates like defer(), concurrency, contextual container attritubes, and more.

Laracon 2024 Updates

Taylor Otwell contributed all of the goodies he shared in his Laracon US 2024 keynote, including chaperone(), defer(), Cache::flexible(), contextual container attributes, and more.

The documentation is being updated; here are a few highlights you should check out to get familiar with these updates:

See Pull Request #52710 for full details on everything added related to Taylor's .

Add minRatio and maxRatio Rules to Dimension Validation

Cam Kemshal-Bell added min and max ratio to the dimensions validation rule:

You can use these methods fluently, using minRatio(), maxRatio(), and ratioBetween():

use Illuminate\Validation\Rule;
 
//
// Using minRatio and maxRatio fluent methods
//
Rule::dimensions()
->minRatio(1 / 2)
->maxRatio(1 / 3);
// dimensions:min_ratio=0.5,max_ratio=0.33333333333333
 
//
// Equivalent using ratioBetween()
//
Rule::dimensions()->ratioBetween(min: 1 / 2, max: 1 / 3);
 
// dimensions:min_ratio=0.5,max_ratio=0.33333333333333

You can also use the string style dimensions rule with this update as well:

use Illuminate\Support\Facades\Validator;
 
Validator::make($request->all(), [
'min_12' => 'dimensions:min_ratio=1/2',
'square' => 'dimensions:ratio=1',
'max_25' => 'dimensions:max_ratio=2/5',
'min_max' => 'dimensions:min_ratio=1/4,max_ratio=2/5',
]);

Backed Enum Support in Gate Methods and Authorize Middleware

Diaa Fares contributed two pull requests that continue to add backed enum support. This release includes updates to the Gate methods and Authorize middleware.

Here are some examples of using Enums with Gate methods:

enum Abilities: string {
case VIEW_DASHBOARD = 'view-dashboard';
case EDIT = 'edit';
case UPDATE = 'update';
}
 
 
// Before
Gate::define('view-dashboard', function (User $user) {
return $user->isAdmin;
});
 
Gate::authorize('view-dashboard');
Gate::inspect('view-dashboard');
Gate::check('view-dashboard');
Gate::any(['edit', 'update], $post);
Gate::none(['edit', 'update]], $post);
Gate::allows('update', $post);
Gate::denies('update', $post);
 
// After
Gate::define(Abilities::VIEW_DASHBOARD, function (User $user) {
return $user->isAdmin;
});
 
Gate::authorize(Abilities::VIEW_DASHBOARD);
Gate::inspect(Abilities::VIEW_DASHBOARD);
Gate::check(Abilities::VIEW_DASHBOARD);
Gate::any([Abilities::EDIT, Abilities::UPDATE], $post);
Gate::none([Abilities::EDIT, Abilities::UPDATE], $post);
Gate::allows(Abilities::UPDATE, $post);
Gate::denies(Abilities::UPDATE, $post);

Here's an example of the Authorize middleware's support for backed enums:

Route::get('/dashboard', [AdminDashboardController::class, 'index'])
->middleware(
Authorize::using(Abilities::VIEW_DASHBOARD)
)
->name(AdminRoutes::DASHBOARD);

Skip Middleware for Queue Jobs

Kennedy Tedesco contributed a Skip middleware to skip a job based on a condition. This middleware has three static constructor methods you can use, including when(), unless(). The job is skipped based on the result of the condition used:

class MyJob implements ShouldQueue
{
use Queueable;
 
public function handle(): void
{
// TODO
}
 
public function middleware(): array
{
return [
Skip::when($someCondition), // Skip when `true`
 
Skip::unless($someCondition), // Skip when `false`
 
Skip::when(function(): bool {
if ($someCondition) {
return true;
}
return false;
}),
];
}
}

Eloquent Collection findOrFail() Method

Steve Bauman contributed a findOrFail() method on Eloquent collections that adds a way to find a model on an already populated collection:

$users = User::get(); // [User(id: 1), User(id: 2)]
 
$users->findOrFail(1); // User
 
$user->findOrFail([]); // []
 
$user->findOrFail([1, 2]); // [User, User]
 
$user->findOrFail(3); // ModelNotFoundException: 'No query results for model [User] 3'
 
$user->findOrFail([1, 2, 3]); // ModelNotFoundException: 'No query results for model [User] 3'

Release notes

You can see the complete list of new features and updates below and the diff between 11.22.0 and 11.23.0 on GitHub. The following release notes are directly from the changelog:

v11.23.0

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
Laravel Idea

Ultimate PhpStorm plugin for Laravel developers, delivering lightning-fast code completion, intelligent navigation, and powerful generation tools to supercharge productivity.

Visit Laravel Idea
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
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
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
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
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
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant 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
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Enhance Validation Testing Precision with Laravel's assertOnlyJsonValidationErrors image

Enhance Validation Testing Precision with Laravel's assertOnlyJsonValidationErrors

Read article
Generate HTTP Fixtures from Live API Calls in Laravel image

Generate HTTP Fixtures from Live API Calls in Laravel

Read article
Confidently Extract Single Array Items with Laravel's Arr::sole() Method image

Confidently Extract Single Array Items with Laravel's Arr::sole() Method

Read article
Safely Retry API calls in Laravel image

Safely Retry API calls in Laravel

Read article
Laravel's AsHtmlString Cast for Elegant HTML Attribute Management image

Laravel's AsHtmlString Cast for Elegant HTML Attribute Management

Read article
NativePHP for Mobile v1 — Launching May 2 image

NativePHP for Mobile v1 — Launching May 2

Read article