Never Miss a Laravel Release 🚀
The Laravel team released v12.18.0, with encrypt and decrypt string helpers, per-request truncation limit for HTTP client responses, a new command option to make batchable jobs, and more:
Encrypt and decrypt Str helper methods
Hristijan Manasijev contributed encrypt() and decrypt() string helper methods, enabling encryption/decryption in fluent string chains:
// Before$encryptedToken = str('secret-api-token') ->pipe(fn(Stringable $str) => encrypt($str->value())) ->prepend('encrypted:') ->append(':end'); // After$encryptedToken = str('secret-api-token') ->encrypt() ->prepend('encrypted:') ->append(':end');
See Pull Request #55931 for details. The Strings documentation now includes encrypt and decrypt methods for stringable instances.
A command option for making batchable jobs
Hafez Divandari contributed a --batched option to the make:job command to make a batchable job:
php artisan make:job ProcessPodcast --batched
The above command generates the following ProcessPodcast class:
namespace App\Jobs; use Illuminate\Bus\Batchable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Queue\Queueable; class ProcessPodcast implements ShouldQueue{ use Batchable, Queueable; /** * Create a new job instance. */ public function __construct() { // } /** * Execute the job. */ public function handle(): void { if ($this->batch()->cancelled()) { // The batch has been cancelled... return; } // }}
Configure a policy using a PHP Attribute
Caleb White contributed a UsePolicy attribute to configure which policy to use with a model. Policies have auto-discovery by convention, and this attribute allows you to be explicit if you want:
#[UsePolicy(PostPolicy::class)]class Post extends Model {}
The UsePolicy attribute can be used to override or verbosely set a policy. While this attribute makes it possible to explicitly set a policy, I recommend learning about policy discovery to learn how Laravel uses conventions to discover policies.
Allow setting the RequestException truncation limit per request
Luke Kuzmish contributed the ability to customize the exception truncation behavior of HTTP client exceptions on a per-request basis:
Http::truncateExceptionsAt(240)->post(/* ... */)
For details, see the HTTP Client error handling documentation.
Release notes
You can see the complete list of new features and updates below and the diff between 12.17.0 and 12.18.0 on GitHub. The following release notes are directly from the changelog:
v12.18.0
- document
through()method in interfaces to fix IDE warnings by @harryqt in https://github.com/laravel/framework/pull/55925 - [12.x] Add encrypt and decrypt Str helper methods by @KIKOmanasijev in https://github.com/laravel/framework/pull/55931
- [12.x] Add a command option for making batchable jobs by @hafezdivandari in https://github.com/laravel/framework/pull/55929
- [12.x] fix: intersect Authenticatable with Model in UserProvider phpdocs by @calebdw in https://github.com/laravel/framework/pull/54061
- [12.x] feat: create UsePolicy attribute by @calebdw in https://github.com/laravel/framework/pull/55882
- [12.x]
ScheduledTaskFailednot dispatched on scheduled forground task fails by @achrafAa in https://github.com/laravel/framework/pull/55624 - [12.x] Add generics to
Model::unguarded()by @axlon in https://github.com/laravel/framework/pull/55932 - [12.x] Fix SSL Certificate and Connection Errors Leaking as Guzzle Exceptions by @achrafAa in https://github.com/laravel/framework/pull/55937
- Fix deprecation warning in PHP 8.3 by ensuring string type in explode() by @Khuthaily in https://github.com/laravel/framework/pull/55939
- revert: #55939 by @NickSdot in https://github.com/laravel/framework/pull/55943
- [12.x] feat: Add WorkerStarting event when worker daemon starts by @Orrison in https://github.com/laravel/framework/pull/55941
- [12.x] Allow setting the
RequestExceptiontruncation limit per request by @cosmastech in https://github.com/laravel/framework/pull/55897 - [12.x] feat: Make custom eloquent castings comparable for more granular isDirty check by @SanderSander in https://github.com/laravel/framework/pull/55945
- [12.x] fix alphabetical order by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/55965
- [12.x] Use native named parameter instead of unused variable by @imanghafoori1 in https://github.com/laravel/framework/pull/55964
- [12.x] add generics to Model attribute related methods and properties by @taka-oyama in https://github.com/laravel/framework/pull/55962
- [12.x] Supports PHPUnit 12.2 by @crynobone in https://github.com/laravel/framework/pull/55961
- [12.x] feat: Add ability to override SendQueuedNotifications job class by @Orrison in https://github.com/laravel/framework/pull/55942
- [12.x] Fix timezone validation test for PHP 8.3+ by @platoindebugmode in https://github.com/laravel/framework/pull/55956
- Broadcasting Utilities by @taylorotwell in https://github.com/laravel/framework/pull/55967
- [12.x] Remove unused $guarded parameter from testChannelNameNormalization method by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/55973
- [12.x] Validate that
outOfis greater than 0 inLotteryhelper by @mrvipchien in https://github.com/laravel/framework/pull/55969 - [12.x] Allow retrieving all reported exceptions from
ExceptionHandlerFakeby @cosmastech in https://github.com/laravel/framework/pull/55972