Support the ongoing development of Laravel.io →
Database Eloquent

Hello, could somebody kick me into right direction how to build this kind of query in eloquent:

SET @msum := 0;
SELECT t1.* 
FROM (
    SELECT m.*,  
          (@msum := @msum + m.amount) AS cumulative_amount
    FROM meetings m 
    WHERE m.type = 'sometype'
    ORDER BY m.date ASC
) t1 
WHERE t1.cumulative_amount <= 7;

What I want to accomplish is that I will get rows of specific type which sum is equal or less than desired amount. Maybe somebody have complete different idea how to achieve same thing in 'eloquentish' way.

Thank you all for help Tom

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lachyn lachyn Joined 23 Oct 2014

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.

© 2025 Laravel.io - All rights reserved.