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

Time:07-06

**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

CodePudding user response:

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.

CodePudding user response:

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

  • Related