Get array of ids using Eloquent ORM
You can use lists() method for getting ids. Let your model name be ‘Test’.
Test::where('id' ,'>' ,0)->lists ('id')->toArray();
You can use the get() method also.
test::where('id' ,'>' ,0)->get('id');
For Laravel versions above 5.2
Pluck() method can be used instead of lists(),because lists() is deprecated.
To get the related ids lists through a many to many relationships. You can use DB class
example:
DB::table('name_of_table')->where('condition')->lists('id');
Comments
0 comments
Please Sign in or Create an account to Post Comments