Laravel 5.5.33 Is Now Available, Learn About What’s in the New Release
Published on by Paul Redmond
Laravel 5.5.33 is now available as of Monday, January 29th with some excellent convenience methods ranging from the query builder to collections and testing.
First up Jonathan Reinink added a “not exists” method to the query builder which is named doesntExist()
:
User::where('email', 'user@example.com')->doesntExist();
Roberto Aguilar added a new test response assertion assertHeaderMissing()
that is the inverse of the assertHeader()
:
$response->assertHeaderMissing('Location');
The Illuminate\Support\Collection
now has a new higher order unique()
, which was contributed by Justin Seliga:
Here’s an example from a php artisan tinker
session if you want to experiment:
use \Illuminate\Support\Collection;>>> $c = new Collection([... ['id' => '1', 'name' => 'first'],... ['id' => '1', 'name' => 'second'],... ['id' => '3', 'name' => 'third'],... ]);>>> $c->unique->id=> Illuminate\Support\Collection {#751 all: [ 0 => [ "id" => "1", "name" => "first", ], 2 => [ "id" => "3", "name" => "third", ], ], }
A Boolean toggle was added to withTrashed()
by Kuba Szymanowski, which decides whether or not to included trashed records:
Model::withTrashed(true)->get(); // Retrieves trashed recordsModel::withTrashed(false)->get(); // Does not retrieve trashed records
The use-case is to avoid a splitting control flow, but you can continue to use withTrashed()
without passing any arguments. Here’s an example to further understand the change:
// New use-casepublic function index(Request $request){ return User::withTrashed($request->showDeleted)->get();} // Before pre-5.5.33, you can continue to do this...public function index(Request $request){ $query = User::query(); if ($request->showDeleted) { $query->withTrashed(); } return $query->get();}
Here are the full release notes for Laravel 5.5.33:
v5.5.33 (2018-01-30)
Added
- Added
notExists()
method to query builder (#22836, 9d2a7ca) - Added
assertHeaderMissing()
assertion (#22849, #22866) - Added support for higher order unique (#22851)
- Added boolean toggle to
withTrashed()
(#22888)