1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel,livewire2.0 TipsAdvent Calendar 2022

Day 1

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

Last updated at Posted at 2022-11-30

概要

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);

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

1
0
0

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
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?