Support the ongoing development of Laravel.io →
posted 7 years ago
Last updated 2 years ago.
0

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.

0
$b = Class::orderBy('created_at', 'desc')->whereRaw( DB::raw('(`id`) % 2 != 0') )->take(50)->get();
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Abhi abhi728 Joined 6 Sep 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.