laravel where字句
laravel where字句
值
->where('name','admin')
->orWhere('name','tom')
区间
->whereBetween('age',[20,30])
->whereNotBetween('age',[20,30])
null
->whereNull('content')
->whereNotNull('content')
数组
->whereIn('id',[1,2,3])
->whereNotIn('id',[1,2,3])
字段
->whereColumn('first_name', 'last_name')
->whereColumn('updated_at', '>', 'created_at')
->whereColumn([
['first_name', '=', 'last_name'],
['updated_at', '>', 'created_at']
])
参数分组
DB::table('users')->where('name', '=', 'John')
->orWhere(function($query){
$query->where('votes', '>', 100)
->where('title', '<>', 'Admin');
})
->get();
//等同于
//select * from users where name = 'John' or (votes > 100 and title <> 'Admin')
注入原生 where 子句
->whereRaw('orders.user_id = users.id');
->orWhereRaw('orders.user_id = users.id');
动态的 Where 字段
->whereNameOrAge('Jane', 22)//name=Jane,age=22
->whereIdAndEmail(2, 'john@doe.com')//id=2,email=john@doe.com