Laravel
Laravel News
The Laravel team released v11.24 this week, with new shorthands for Process fakes, a nullOnUpdate()
method for foreign key definitions, support for retrying multiple batch IDs when retrying jobs, and more.
A quick note that as of the time of writing, auto-discovery of console commands in the app/Console/Commands
path was broken in v11.24.0. This issue was quickly patched in v11.24.1.
I'd recommend waiting for a patch update, but this could confuse you if you update and application console commands are missing.
prependLocation()
to View FactoryNoboru Shiroiwa added the prependLocation()
method to the View factory, which enables you to use the method with the View
facade:
// Before
View::getFinder()->addLocation($path); // ✅
View::getFinder()->prependLocation($path); // ✅
View::addLocation($path); // ✅
View::prependLocation($path); // ❌
// After
View::prependLocation($path); // ✅
nullOnUpdate()
Method to ForeignKeyDefinitionGisu Nasrollahi contributed a nullOnUpdate()
method to the ForeignKeyDefinition
schema class, which indicates that updates on the referenced model should set the foreign key value to null.
$table->foreign('user_id')
->references('id')
->on('users')
->nullOnUpdate();
BackedEnum
to be Used With Route::can()
@Omegadela contributed support for backed enums in the Route::can()
method:
// Before
Route::post('/request', function () {...})->can(Permissions::CAN_REQUEST->value);
// After
Route::post('/request', function () {...})->can(Permissions::CAN_REQUEST);
Process
FakesJason McCreary contributed two new result shorthands for Process
fake results in tests. The first example is a shorthand to set the exit code. The second example is a shorthand for throwing an exception.
Process::fake([
'php -l script.php' => 255,
'cat README.txt' => new \RuntimeException('fake exception message'),
]);
Here's an example of the fake in action from the Pull Request's tests:
// Exit code example
$factory = new Factory;
$factory->fake(['ls -la' => 1]);
$result = $factory->run('ls -la');
$this->assertSame(1, $result->exitCode());
$this->assertFalse($result->successful());
// Exception example
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('fake exception message');
$factory = new Factory;
$factory->fake(['cat me' => new \RuntimeException('fake exception message')]);
$factory->run('cat me');
Sean Kegel updated the queue:retry-batch
command to accept multiple IDs so that multiple jobs can be retried at once:
php artisan queue:retry-batch \
'9d0ed667-8c3a-4385-8a07-aff118a21e5c' \
'9d0ed6f1-b8dd-486b-8761-f89de0fb68e3'
You can see the complete list of new features and updates below and the diff between 11.23.0 and 11.24.0 on GitHub. The following release notes are directly from the changelog:
$name
variable in non base config file becomes it's key by @rojtjo in https://github.com/laravel/framework/pull/52738
BackedEnum
to be passed to Route::can()
by @Omegadela in https://github.com/laravel/framework/pull/52792
Concurrency
Configuration Index Name by @devajmeireles in https://github.com/laravel/framework/pull/52788
withoutPretending
method properly resets state after callback execution by @xurshudyan in https://github.com/laravel/framework/pull/52794
ProcessDriver[@defer](https://github.com/defer)()
to ProcessDriver[@run](https://github.com/run)()
method by @rodrigopedra in https://github.com/laravel/framework/pull/52807
Concurrency\ProcessDriver
by @rodrigopedra in https://github.com/laravel/framework/pull/52813
Illuminate\Support\defer
function by @crynobone in https://github.com/laravel/framework/pull/52801
laravel/serializable-closure
on Database component by @crynobone in https://github.com/laravel/framework/pull/52835
Process
fakes by @jasonmccreary in https://github.com/laravel/framework/pull/52840
laravel/prompts
v0.2 by @crynobone in https://github.com/laravel/framework/pull/52849
[@throws](https://github.com/throws)
section to Concurrency manager doc block by @rnambaale in https://github.com/laravel/framework/pull/52856
routes/console.php
by @SamuelNitsche in https://github.com/laravel/framework/pull/52867
touchesParents()
for chaperoned models by @samlev in https://github.com/laravel/framework/pull/52883
Cache::flexible
improvements by @timacdonald in https://github.com/laravel/framework/pull/52891
\DateTimeInterface
and \DateInterval
to type for Cache::flexible()
by @bram-pkg in https://github.com/laravel/framework/pull/52888
The post Laravel 11.24 Released appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.