![](/img/trans.png)
[英]Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given,
[英]Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array
**singers_id 是数组 ["2","4"] **
我的控制器
$albums = Album::join('tracks', 'albums.artist_id', '=', 'tracks.artist_id')
->where('albums.verified',1)->get();
我的刀片
@php
$names = DB::table('singers')->whereIn('id', $album->singers_id)->pluck('singers_name')->toArray();
@endphp
{{implode(' & ', $names)}}
</a></span>
错误 -laravel Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array, string given in laravel
如何解决此错误
使用->whereIn()
时,您的第二个参数必须是一个数组。 您当前正在传递字符串。 此外,在刀片文件中执行数据库查询也不是一个好习惯。
改变你的线路
$names = DB::table('singers')->whereIn('id', $album->singers_id)->pluck('singers_name')->toArray();
至
$names = DB::table('singers')->whereIn('id', [$album->singers_id])->pluck('singers_name')->toArray();
whereIn
value 必须是array
,看起来像你把int
代替
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.