简体   繁体   中英

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

**singers_id is array ["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

how to solve this error

When using ->whereIn() , your second parameter must be an array. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM