Find max value of a column in laravel

The correct syntax is:

Cliente::max('id')

https://laravel.com/docs/5.5/queries#aggregates


Laravel makes this very easy, in your case you would use

$maxValue = Cliente::max('id');

But you can also retrieve the newest record from the table, which will be the highest value as well

$newestCliente = Cliente::orderBy('id', 'desc')->first(); // gets the whole row
$maxValue = $newestCliente->id;

or for just the value

$maxValue = Cliente::orderBy('id', 'desc')->value('id'); // gets only the id

Or, if you have a created_at column with the date you could get the value like this

$maxValue = Cliente::latest()->value('id');

Relevant Laravel Documentation: https://laravel.com/docs/5.5/queries#aggregates