It is possible if you don't hesitate to use a raw sql query.
SELECT *
FROM (
SELECT
@row := @row +1 AS rownum, firstname, lastname
FROM (
SELECT @row :=0) r, users
) ranked
where rownum % 3 = 1
For more information about raw queries please see the Laravel Documentation.
$b = Class::orderBy('created_at', 'desc')->whereRaw( DB::raw('(`id`) % 2 != 0') )->take(50)->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community