LoginSignup
0
1

More than 3 years have passed since last update.

Laravel クエリビルダー メモ

Posted at

よく忘れるのでメモ
※随時追加していく

ANDとORの入れ子かつ変数を使いたいとき

orWhereuse を使う

条件の例(まともな例じゃないけどとりあえず)
active = 1 かつ
((price < 100 かつ status = 1) または (fruit = 'apple' かつ status = 2))

$price = 100;
$fruit = 'apple';

$foo = Foo::where('active', 1)
    ->where(function ($query) use ($price) {
        $query->where('price', '<' $price)
            ->where('status', 1);
    })
    ->orWhere(function ($query) use ($fruit) {
        $query->where('fruit', $fruit)
            ->where('status', 2);
    })
    ->get() 

複数の条件でjoinSubするやつ(あとで書く)

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