LoginSignup
0

posted at

updated at

まさかCollectionにwhereしてcontainsしてないか?

概要

Collectionの中に同じ値があるかどうかにcontainsを使うと思いますが、こんな使い方してませんか?

$schedules
->where('start_time',$statTime)
->where('end_time',$endTime)
->contains('date',$date)

クロージャ書けるよ

ドキュメントに書いてはある

$schedules->contains(fn($schedule, $key) => 
    $schedule->date === $date && $schedule->start_time === $statTime && $schedule->end_time === $endTime);

書いてあるのに目がスルーしてました。クロージ書ける事を最近知りました。。。。
処理速度計測してみるとまぁ当然のようにこっちの方が早かったです。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0