[英]How to use array with LIKE with whereIn to retrieve eloquent rows in Laravel
[英]How to use WhereIn with Eloquent in laravel?
我想在 Eloquent 中使用 WhereIn 方法,但现在它的工作方式如下
消息: Call to undefined method Illuminate\\Database\\Query\\JoinClause::whereIn()
Class Notificatin extends Model{
public function getNotification($user_id)
{
$this->_data = self::select('*')
->join('user_permission', function($join){
$join->on('n_user_id','=','user_id')->whereIn('permission_id',array(90,91,92,93));
})
->get();
if (count($this->_data)) {
return $this->_data;
} else {
return $this->_data;
}
}
}
您需要修改join
查询并将whereIn
clouse 放在外面,例如:
$this->_data = self::select('*')
->join('user_permission', function($join){
$join->on('n_user_id','=','user_id');
})->whereIn('user_permission.permission_id',array(90,91,92,93))
->get();
不使用 Joins :
whereIn / whereNotIn / orWhereIn / orWhereNotIn
whereIn 方法验证给定列的值是否包含在给定数组中:
$users = DB::table('users')
->whereIn('id', [1, 2, 3])
->get();
whereNotIn 方法验证给定列的值不包含在给定数组中:
$users = DB::table('users')
->whereNotIn('id', [1, 2, 3])
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.