prgrm
prgrm

Reputation: 3833

Choosing the next number from another table in a query in Laravel

I have a variable $a which is an integer.

Then I have a table with a row called MaxValue.

I want to do an eloquent query to find the first MaxValue ocurrence bigger than $a.

I can do it easily with SQL but I would rather do it correctly with Eloquent.

Something like this:

Item::where('MaxValue', '>=',$a)->first();

Upvotes: 0

Views: 26

Answers (1)

Siraj ul Haq
Siraj ul Haq

Reputation: 885

You can try something like this:

Item::where('MaxValue', '>=', $a)->order_by('MaxValue', 'desc')->first();

Upvotes: 1

Related Questions