简体   繁体   English

Illuminate\Database\Query\Builder::cleanBindings(): 参数 #1 ($bindings) 必须是数组类型

[英]Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array

**singers_id is array ["2","4"] ** **singers_id 是数组 ["2","4"] **

my cotroller我的控制器

  $albums =  Album::join('tracks', 'albums.artist_id', '=', 'tracks.artist_id')
        ->where('albums.verified',1)->get();

my blade我的刀片

   @php
                    
                    
                    $names = DB::table('singers')->whereIn('id', $album->singers_id)->pluck('singers_name')->toArray();
    
@endphp
{{implode(' & ', $names)}}
</a></span>

error -laravel Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array, string given in laravel错误 -laravel Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array, string given in laravel

how to solve this error如何解决此错误

When using ->whereIn() , your second parameter must be an array.使用->whereIn()时,您的第二个参数必须是一个数组。 You're currently passing string.您当前正在传递字符串。 Also it's not a good practice to execute database queries inside blade file.此外,在刀片文件中执行数据库查询也不是一个好习惯。

Change your line改变你的线路

 $names = DB::table('singers')->whereIn('id', $album->singers_id)->pluck('singers_name')->toArray();

to

 $names = DB::table('singers')->whereIn('id', [$album->singers_id])->pluck('singers_name')->toArray();

whereIn value must be array , look like you put int instead whereIn value 必须是array ,看起来像你把int代替

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 传递给 Illuminate\\Database\\Query\\Builder::cleanBindings() 的参数 1 必须是数组类型,给定的字符串, - Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given, 传递给 Illuminate\Database\Eloquent\Builder::create() 的参数 1 必须是数组类型 - Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array 传递给 Illuminate\\Database\\Query\\Builder::update() 的参数 1 必须是数组类型,给定的字符串,调用 - Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in laravel 错误 传递给 Illuminate\Database\Query\Builder::whereBetween() 的参数 2 必须是数组类型 - laravel err Argument 2 passed to Illuminate\Database\Query\Builder::whereBetween() must be of the type array 类型错误:传递给 Illuminate\\Database\\Eloquent\\Builder::create() 的参数 1 必须是数组类型,给定的对象,在 laravel 中调用 - Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, object given, called in laravel 类型错误:传递给 Illuminate\Database\Eloquent\Builder::create() 的参数 1 必须是数组类型,给定 null - Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, null given Laravel与MongoDB:传递给Illuminate \\ Database \\ Query \\ Builder :: __ construct()的参数2必须是Illuminate \\ Database \\ Query \\ Grammars的实例 - Laravel with MongoDB: Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must be an instance of Illuminate\Database\Query\Grammars 传递给Illuminate \\ Database \\ Grammar :: parameterize()的参数1必须为数组类型-Laravel - Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array - Laravel 不能使用 Illuminate\\Database\\Query\\Builder 类型的对象作为数组 - Cannot use object of type Illuminate\Database\Query\Builder as array Laravel 模型批量更新 - Builder::cleanBindings() 必须是数组类型,给定 null - Laravel Model Bulk Update - Builder::cleanBindings() must be of the type array, null given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM