Laravel 11.24 Released

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. This issue likely gets patched quickly, but if you want to update to 11.24.0, you can add the following to bootstrap/app.php:

Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withCommands([
        __DIR__.'/../app/Console/Commands'
    ]);

I'd recommend waiting for a patch update, but this could confuse you if you update and application console commands are missing.

Add prependLocation() to View Factory

Noboru 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);              // ✅

Add nullOnUpdate() Method to ForeignKeyDefinition

Gisu 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();

Allow 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);

Add Result Shorthands for Process Fakes

Jason 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');

Support Multiple Batch IDs When Retrying Failed Batch Jobs

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'

Release notes

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:

v11.24.0


The post Laravel 11.24 Released appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

Read more

© 2024 Extly, CB - All rights reserved.