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.

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

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant 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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

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

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article