[英]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.