【发布时间】:2021-03-11 21:00:33
【问题描述】:
当我尝试在 laravel 中使用 whereIn 获取帖子时,出现此错误:
Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given, called in
但我将参数作为数组传递,下面我将发布代码,提前谢谢。
$arrayRecived = json_decode($request->fallowList);
var_dump($arrayRecived);
$result = DB::table('posts')->leftJoin('post_votes', function($join) {
$recived = auth()->userOrFail();
$join->on('posts.id', '=', 'post_votes.post_id')->where('post_votes.user_id', '=', $recived['id']);
})->select('posts.id', 'posts.user_id', 'posts.description', 'vote', 'posts.votes', 'posts.filename')
->whereIn('posts.user_id', '=', $arrayRecived)
->orderBy('posts.id', 'desc')->get();
return response()->json(['posts' => $result], 200);
如果我在$arrayRecived 上执行var_dump(),在我执行json_decode() 之后,它会说是一个数组,在控制台中就像:
array(2) {
[0]=>
int(3)
[1]=>
int(9)
}
【问题讨论】: