How to Do following Query in Laravel Eloquent?
SELECT catID, catName, imgPath FROM categories WHERE catType = "Root"
I have tried following
CategoryModel::where('catType', '=', 'Root')
->lists('catName', 'catID', 'imgPath');
but its return only two fields.
Array ( [7] => Category 1 )
From laravel version 5.3^
lists()
is deprecated and functionpluck()
is used instead.pluck()
returns a collection and if you need a simple array just prepend->toArray()
to it.lists()
turns the resulting collection into an array with key value. You can only have two database columns in there. Otherwise you have to useselect()
but then you will get a collection of models not just an array.Selecting multiple columns
Works with Laravel 5.3 too!