【问题标题】:Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given, called in Error but i pass array传递给 Illuminate\Database\Query\Builder::cleanBindings() 的参数 1 必须是数组类型,给定字符串,在错误中调用,但我传递数组
【发布时间】: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)
}

【问题讨论】:

    标签: laravel where-in


    【解决方案1】:

    whereIn() 只带2个参数,其中第二个是数组。因此,以下更改应该可以使其正常工作。

    ->whereIn('posts.user_id', $arrayRecived)
    

    奖励,如果你想做 != 等效,它应该是。

    ->whereIn('posts.user_id', $arrayRecived, 'and', true)
    

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      • 2020-02-23
      • 1970-01-01
      • 2018-04-19
      • 2018-05-28
      相关资源
      最近更新 更多