Laravel 8.61 Released

News

September 15th, 2021

laravel8.jpg

The Laravel team released 8.61 with a delete or fail() model method, a value or fail model method, assert if a model exists in a test and the latest changes in the v8.x branch.

Delete or Fail Model Method

Claas Augner contributed a deleteOrFail() method that makes it more convenient to handle model delete errors and less verbose than checking the return value of delete():

1try {
2 $model->deleteOrFail();
3} catch (\Throwable $e) {
4 // ...
5}

Assert If a Model Exists Test Method

@RVxLab contributed a assertModelExists() testing method to test whether a model exists in the database. Taylor Otwell also added a assertModelMissing method:

1$product = Product::find(1);
2 
3// ...
4$this->assertDatabaseHas('products', [
5 'id' => $product->getKey(),
6]);
7 
8$this->assertModelExists($product);
9 
10$this->assertModelMissing($product);

Value or Fail Model Method

In the only new feature of Laravel 8.60, @Italo contributed a valueOrFail() method, which gets a single column's value from the first result of a query or throws an exception:

1// Before:
2$votes = User::where('name', 'John')->firstOrFail('votes')->votes;
3 
4// Now:
5$votes = User::where('name', 'John')->valueOrFail('votes');

Allows Tests to Utilize the Null Logger

Tim MacDonald contributed a new update where tests can utilize the null logger. Check out Pull Request #38785 for more details on the situation and updates made.

Create a Policy While Creating a Model

Tim Fevens contributed a --policy flag, which is also included with the --all flag as well:

1php artisan make:model --policy Post

Release Notes

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

v8.61.0

Added

  • Added possibility compare custom date/immutable_date using date comparison (#38720)
  • Added policy option to make:model (#38725
  • Allow tests to utilise the null logger (#38785)
  • Added deleteOrFail to Model (#38784)
  • Added assertExists testing method (#38766)
  • Added forwardDecoratedCallTo to Illuminate/Database/Eloquent/Relations/Relation (#38800)
  • Adding support for using a different Redis DB in a Sentinel setup (#38764)

Changed

  • Return on null in Illuminate/Queue/Queue::getJobBackoff() (27bcf13)
  • Provide psr/simple-cache-implementation (#38767)
  • Use lowercase for hmac hash algorithm (#38787)

v8.60.0

Added

  • Added the valueOfFail() Eloquent builder method (#38707)

Reverted

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.