Laravel —How to get maximum minimum average value and sum of a column — query builder method
Laravel query builder provides a variety of aggregate methods such as
sum. You may call any of these methods after constructing your query.
$users = DB::table('users')->count();
$price = DB::table('orders')->max('price');
You may combine these methods with other clauses:
$price = DB::table('orders')
If you want to find the maximum id number of a table you have some options in Laravel:
use App\User; // set at the top
The alternative is:
$newestUser = User::orderBy('id', 'desc')->first();
$maxId = $newestUser->id;
if you have a
created_at column with the date you could get in Laravel the maximum id value like this:
$maxId = User::latest()->value('id');
Thank you for reading! If you enjoyed this article:
Clap it ! Share it! Follow Me in Medium!
Panjeh — Medium
Read writing from Panjeh on Medium. Physicists PhD, Self-taught web developer #Learning, #laravelphp #Vuejs. Every day…
Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.
Have a very wonderful day!