Home > Software design >  Laravel binding params
Laravel binding params

Time:02-10

I am using below query to get results of 4 id's, but it shows only one result

$id = array(6,7,8,9);      
        $params = array(
            'connection' => 'redis',
            'id' => implode(',',$id)
        );

        $result =  DB::select(
            DB::raw("
                SELECT 
                    * 
                FROM 
                    failed_jobs 
                WHERE 
                    id IN (:id) AND 
                    connection = :connection
            "), $params);

CodePudding user response:

The best way to go about it is to use the query builder instead. This is much cleaner since it provides the whereIn clause:

$id = array(6,7,8,9);

$result = DB::table('failed_jobs')
    ->where('connection', 'redis')
    ->whereIn('id', $id)
    ->get();
  • Related