LoginSignup
0
0

More than 3 years have passed since last update.

Eloquent のいろんなwhere

Last updated at Posted at 2020-09-07

単純なwhere

$query->where('col1', $val1)
$query->where('col1', '<>', $val1)

where でAND

$query->where('col1', $val1)->where('col2', $val2)

where でOR

$query->where('col1', $val1)->orWhere('col2', $val2)

where で複数値

$query->whereIn('col1', array($val1,$val2))
$query->whereNotIn('col1', array($val1,$val2))

where でNull

$query->whereNull('col1')
$query->whereNotNull('col1')

where で(A AND B) Or (C or D)など

$query->where(function($query) use($val1,$val2){
        $query->where('col1',$val1)
              ->where('col2',$val2)
      })
      ->orWhere(function($query) use($val3,$val4){
        $query->where('col3',$val3)
              ->where('col4',$val4)
      })
0
0
1

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
0