LoginSignup
1
1

More than 5 years have passed since last update.

LaravelでDBから取ってきたデータの中に指定したキーと値の組み合わせがあるか調べる

Posted at

LaravelでDBから取ってきたデータの中に指定したキーと値の組み合わせがあるか調べるメソッドで便利そうなものがあったので簡単に紹介。


// DBからデータをとってくる
$users = DB::table('user')->get();

// とってきたデータの中にキーがnameで値がtaroのものがあるかどうかを返す。
$users->contains('name', 'taro');

bool $collection->contains(key, value);

参考
ReadDouble
Laravel 5.5 コレクション
https://readouble.com/laravel/5.5/ja/collections.html#method-contains

1
1
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
1