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

Laravel 9.42 comes with new singleton route resources, conditional report helpers, and more

Published on by

Laravel 9.42 comes with new singleton route resources, conditional report helpers, and more image

The Laravel team released 9.42 this week with singleton route resources, conditional report helpers, and more:

Define routes for singleton resources

Jess Archer contributed a Route::singleton() method to register routes for singleton resources. These are resources that are either "one of one" or "zero or one" resources. For example, a profile endpoint:

Route::singleton('profile', ProfileController::class);
/*
Defines:
GET /profile
GET /profile/edit
PUT/PATCH /profile
DELETE /profile
*/
 
// Nested resource
Route::singleton('videos.thumbnail', VideoThumbnailController::class);
 
/*
Defines:
GET /videos/{video}/thumbnail
GET /videos/{video}/thumbnail/edit
PUT/PATCH /videos/{video}/thumbnail
DELETE /videos/{video}/thumbnail
*/
 
// Only and except
Route::singleton('profile', ProfileController::class)
->except('destroy');
 
Route::singleton('profile', ProfileController::class)
->only(['show', 'update']);

The make:controller command was also updated to include --singleton and --creatable flags to generate singleton controllers.

Check out the Singleton Resource Controllers docs for more examples and details. Excellent work, Jess!

Added a rest option for queue:listen

@PHPGuus contributed a --rest= option to the queue:listen command that will sleep for the number of seconds passed to rest:

php artisan queue:listen --rest=5

Determine if a string is a ULID

Michael Nabil contributed an isUlid() method to the Stringable class to check if a string is a valid Universally Unique Lexicographically Sortable Identifier (ULID) string. You can use it as follows:

use Illuminate\Support\Str;
 
Str::isUlid('01GJSNW9MAF792C0XYY8RX6QFT'); // true
Str::of('01GJSNW9MAF792C0XYY8RX6QFT')->isUlid(); // true

Conditional report helpers

Michael Nabil contributed two new conditional report() helpers. These might be useful to shorten checks where you might report when a condition is true or false:

// Normal report usage
if(! Auth::user()->isAdmin()){
report('Is route need permission user');
}
 
// Shorten/avoid `if` with:
report_if(
Auth::user()->isAdmin(),
'Is route need permission admin'
);
 
report_unless(
Auth::user()->isAdmin(),
'Is route need permission user'
);

These helpers are optional—you are free to use them or not :)

Custom mutex name of scheduled events

Andrej Mihaliak contributed a callback to resolve a custom mutex name of scheduled events:

$schedule->command('do-something', ['--uuid' => 'b4d5f926-e1b5-4285-b068-cf1d623a0635'])
->description('Do something important.')
->everyFiveMinutes()
->onOneServer()
->withoutOverlapping()
->createMutexNameUsing(fn (Event $event) => 'schedule-task-'.sha1($event->description));

Check out Pull Request #45126 for complete details.

Release Notes

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

v9.42.0

Added

  • Added --rest option to queue:listen (00a12e2, 82fde9e)
  • Added Illuminate/Support/Stringable::isUlid() (#45100)
  • Add news report_if and report_unless helpers functions (#45093)
  • Add callback to resolve custom mutex name of schedule events (#45126)
  • Add WorkOptions to WorkerStopping Event (#45120)
  • Added singleton and creatable options to Illuminate/Routing/Console/ControllerMakeCommand (#44872)

Fixed

  • Fix pure enums validation (#45121)
  • Prevent test issues with relations with the $touches property (#45118)
  • Fix factory breaking when trying to determine whether a relation is empty (#45135)

Changed

  • Allow set command description via AsCommand attribute (#45117)
  • Updated Mailable to prevent duplicated recipients (#45119)
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.

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
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
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
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
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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
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 →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article