Thursday, 15 April 2021

Laravel Eloquent ORM laravel 5 Get Array of ids

 UPDATE: (For versions >= 5.2)

The lists() method was deprecated in the new versions >= 5.2, now you could use pluck() method instead :

test::where('id' ,'>' ,0)->pluck('id')->toArray();

NOTE: If you need a string, for example in a blade, you can use function without the toArray() part, like:

test::where('id' ,'>' ,0)->pluck('id');
Result 
Array ( 1,2 )

https://stackoverflow.com/questions/34308169/eloquent-orm-laravel-5-get-array-of-ids

No comments:

Post a Comment