N
N
NubasLol2018-09-20 11:48:12
Laravel
NubasLol, 2018-09-20 11:48:12

Laravel Find method how to use it or another?

I pass an array of sorted id to the find method, it also returns models sorted from the smallest id . Which breaks my whole logic. How would you recommend fixing this?
I write a pure sql query and get id . Perhaps you can somehow immediately connect it with the base by d?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-09-20
@swede2k

$ids = [12, 2, 3];
$users= \App\User::find($ids)->sortBy(function ($user) use ($ids) {
    return array_search($user->getKey(), $ids);
});

V
Vladimir Letyagin, 2018-09-20
@JorryGo

I think this will help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question