Thursday, March 30, 2017

Laravel - Get specific rows first from db

So I want to "fix" the first three results in my array, that I get from my be so here is my example:

$ids = explode(',', '2,3,1');

$result = Items::whereIn('id', $ids)
                    ->where('active', '1')
                    ->get();

So I want this to return an array where the id 2 is the first, then 2, then 1. The order of the id's will be determent different each time, so I can't do something like order by id etc.



via JulianNikolaz

Advertisement