[Laravel] 5.7.10がリリースされました
laravel/frameworkのバージョン5.7.10がリリースされました。更新された機能について確認していきます。
Added
1. Eloquent CollectionにloadCount()メソッドが追加されました #25997
取得済みのEloquent Collectionに関連するリレーションの数を取得することができます。
php
$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);テストも追加されていますので、気になる方はこちら
2. PostgreSQL 10+のIdentity columnsに対応しました #26096
3. assertSoftDeleted()メソッドが追加されました #26133, #26148
以下のようにレコードが論理削除済みかを確認できます。
php
$this->assertSoftDeleted($user);
// プライマリーキー指定
$this->assertSoftDeleted('users', ['id' => $user->id]);4. apiResourceでexcept()メソッドを利用できるようになりました #26149
5. テスト時にmock()とspy()が追加されました #26171, b50f9f3
Mockeryなどの利用がとても簡単になりました。
php
$this->mock(Mailer::class, function ($mock) {
$mock->shouldReceive('send')->once();
});
$this->spy(Dispatcher::class, function ($mock) {
$mock->shouldReceive('dispatch')->andReturn(false);
});6. uuidのバリデーションが追加されました #26135
5.6で追加されたStr::orderedUuid()などで生成したuuidに関するバリデーションです。
以下のように利用できます。
php
$request->validate([
'id' => 'required|uuid'
]);7. Notificationのテスト時にlocaleを評価することができるようになりました #26205
詳しい変更については以下を確認してください。