Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

you forgot the get()

$maxVal = model::where(x)->max(column)->get();
0

astroanu said:

you forgot the get()

$maxVal = model::where(x)->max(column)->get();

That doesn't work. Max gives an integer result. And you can't call ->get() on a number. You get the error 'call to a member function get() on a non-object'.

0

I hate to bump, but I'm still lost on how to make this work a week later here.

0

I don't know if this is the 'right' solution or the best way. But it seems to work for me for now. So I'll post it in case it helps someone else. Pretty sure there has to be a better way, but maybe not.

What I did, was check if the results were numeric. If they are numeric, then add stuff, if not numeric (when it returns Builder), then I make different math.

if (is_numeric($maxVal)) {
    $nextNum = $maxVal + 1;
} else {
    $maxVal = 0;
    $nextNum = 1;

If there is a better way, please feel free to chime in!

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Nertskull nertskull Joined 3 Apr 2015

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.