I'm using Eloquent ORM laravel 5.1, i want to return an array of ids greater than 0, My model called
test
$test=test::select('id')->where('id' ,'>' ,0)->get()->toarray();
Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [id] => 2 ) )
Array ( 1,2 )
Try the following code :
test::where('id' ,'>' ,0)->lists('id')->toArray();
NOTE : Better if you define your Models in Camel Case
format, e.g Test
.
UPDATE : (for version 5.2)
The lists
method was deprecated in the new version 5.2
use pluck method instead :
test::where('id' ,'>' ,0)->pluck('id')->toArray();
Hope this helps.