L
L
lynnikvadim2015-08-29 22:02:54
Laravel
lynnikvadim, 2015-08-29 22:02:54

How to select multiple records from db in Laravel?

There is a table, in it more than 100 records.
How can I get multiple records in random order?
Out of order. For example: 1st, 6th, 54th, 74th, 85th.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Evgrafovich, 2015-08-29
@Tantacula

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

V
Vyacheslav Plisko, 2015-08-30
@AmdY

There seems to be no native function now, but you can do this for mysql.
ModelName::orderBy(DB::raw('RAND()'))->take(10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question