Laravel 5.7.10 Released

Published on by

Laravel 5.7.10 Released image

The Laravel team shipped Laravel 5.7.10 yesterday with a handful of new features, fixes, and changes:

loadCount Eloquent Collection Method

First up, is the ability to load relationship counts on an Eloquent collection. Before this feature, you could only load relationships, but now you can call loadCount() to get counts for all relations.

The pull request illustrates how you could use loadCount() with the following example:

$events = Event::latest()->with('eventable')->paginate();
 
$groups = $events->map(function ($event) {
return $event->eventable;
})->groupBy(function ($eventable) {
return get_class($eventable);
});
 
$groups[Post::class]->loadCount('comments');
$groups[Comment::class]->loadCount('hearts');
 
return new EventIndexResponse($events);

Now all the eventable models would have a count value for comments or hearts respectively. The loadCount feature was added by Tim MacDonald. Tim is the author of the Laravel Log Fake package that we featured earlier this month. Nice work Tim!

Pass a Model to assertSoftDeleted

You can use the assertSoftDeleted to assert that a model has been soft deleted. Before Laravel 5.7.10, the method call might look something like the following:

$this->assertSoftDeleted('users', [
'id' => $user->id,
'name' => $user->name,
'email' => $deletedUser->email,
]);

Now, thanks to an update to the assertSoftDeleted method, you can pass the model directly which will assert against the table’s primary key and primary key value:

$this->assertSoftDeleted($user);
 
// Same as:
$this->assertSoftDeleted('users', ['id' => $user->id]);

Thanks to Dwight Watson for this nice shortcut!

Add Mock and Spy Objects to the Container

Titas Gailius added the ability to more conveniently add mock and spy instances to the container in a test:

$this->mock(Mailer::class, function ($mock) {
$mock->shouldReceive('send')->once();
});
 
 
$this->spy(Dispatcher::class, function ($mock) {
$mock->shouldReceive('dispatch')->andReturn(false);
});

These methods are syntactic sugar for something like the following:

$this->instance(Mailer::class, Mockery::mock(Mailer::class, function ($mock) {
$mock->shouldReceive('send')->once();
}));

UUID Validation

André Filipe contributed a UUID validation method which uses a regex to avoid dependency of ramsey/uuid in the illuminate/validation component.

The name of the validation rule is uuid:

$request->validate([
'post' => 'required|uuid'
]);

Notification Fake can Assert a Preferred Locale

Derek MacDonald added the ability to assert the preferred notification fake locale on notifications that implement the HasLocalePreference interface:

Notification::fake();
 
$user = factory(User::class)->create(['locale' => 'au']);
 
// Call an artisan console command that invokes:
Notification::send($user, new AFLTrade('Chad Wingard', 'Hawthorn'));
 
Notification::assertSentTo($user, AFLTrade::class, function ($notification, $channels, $notifiable, $locale) use ($user) {
return $notification->player === 'Chad Wingard' &&
$notification->club === 'Hawthorn' &&
$notifiable === $user &&
$locale === 'au';
});

You can see the full diff between 5.7.9 and 5.7.10 on GitHub, and the full release notes below from the 5.7 changelog:

v5.7.10

Added

  • Added loadCount method to eloquent collections (#25997)
  • Added support for identity columns in PostgreSQL 10+ (#26096)
  • Allowed passing a model instance directly to assertSoftDeleted method in Foundation/Testing/Concerns/InteractsWithDatabase.php (#26133 , #26148)
  • Added possibility to define exclude methods on registered apiResource (#26149)
  • Added filp/whoops to suggest in composer.json (#26180)
  • Added mock and spy methods to Foundation/Testing/Concerns/InteractsWithContainer.php (#26171, b50f9f3)
  • Added uuid validation rule to validator (#26135)
  • NotificationFake can assert preferred locale (#26205)

Fixed

  • Fixed whereHas and $withCount bindings from polymorphic relationships (#26145)
  • Fixed getTable method in Model (#26085)
  • Fixed filesystem locking hangs in PackageManifest::build() (#26010, 98b8256)
  • Fixed Illuminate/Http/Testing/File.php for Symfony 4.1 components (#26080)
  • Fixed URL in Notifications/resources/views/email.blade.php (22ca105)
  • Fixed hasValidSignature method when someone send a null signature in UrlGenerator.php (#26132)
  • Fixed autocomplete for container in ServiceProvider for cases when someone developed packages (#26063)
  • Fixed ColumnDefinition::default typehint (#26041)

Changed

  • Define mix as const in react-stubs/webpack.mix.js and vue-stubs/webpack.mix.js presets (#26119)
  • Make assertSessionHasNoErrors in TestResponse.php print the unexpected errors (#26039, e6bdf8a)
  • Replaced the remaining occurrences of newQuery() to newModelQuery() in UPDATE/DELETE queries. (#26158)
  • Improved findOrFail() exceptions in BelongsToMany.php and HasManyThrough.php relations (#26182)

Changed realization

  • Reversed ternary condition in Arr::wrap to make it clearer (#26150)
  • Simplified formatAction in UrlGenerator.php (#26121)
  • Simplified isChainOfObjects method in Support/Testing/Fakes/QueueFake.php (#26151)
  • Deleted unneeded code (#26053, #26162, #26160, #26159, #26152)
  • Prefer stricter comparison (#26139, #26157)
  • Removed duplicated code from Router::updateGroupStack method (#26206, 6debff6)
Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Forge
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with VILT and TALL stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Sort Elements with the Alpine.js Sort Plugin image

Sort Elements with the Alpine.js Sort Plugin

Read article
Anonymous Event Broadcasting in Laravel 11.5 image

Anonymous Event Broadcasting in Laravel 11.5

Read article
Microsoft Clarity Integration for Laravel image

Microsoft Clarity Integration for Laravel

Read article
Apply Dynamic Filters to Eloquent Models with the Filterable Package image

Apply Dynamic Filters to Eloquent Models with the Filterable Package

Read article
Property Hooks Get Closer to Becoming a Reality in PHP 8.4 image

Property Hooks Get Closer to Becoming a Reality in PHP 8.4

Read article
Asserting Exceptions in Laravel Tests image

Asserting Exceptions in Laravel Tests

Read article