jeudi 30 mars 2017

Laravel Eloquent query not working

the below query is working in SQL but when i tried in eloquent not getting expected data

// SQL working
SELECT id,first_name,last_name,phone_number,registration_id FROM drivers WHERE first_name LIKE "A%" ORDER BY first_name ASC LIMIT 5 OFFSET 0


//Laravel eloquent, result not as expected, getting all the data with limit of 5
    public function getSearchList($alphabet, $limit)
    {
        //dd($alphabet, $limit);
        $drivers = Driver::select('id','first_name','last_name','phone_number','registration_id')
                   ->where('first_name', 'like', '%'.$alphabet.'%')
                   ->orderBy('first_name', 'asc')
                   ->limit(5)->offset($limit)
                   ->get();

        if (count($drivers) == 0) {
            return $this->respondNotFound();
        }

        return Response::json([
            'data' => $drivers->all()
        ]);
    }

thank you



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2oaIvRA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire