php - Count my totals up - Laravel 5.2 -


i have "orders" table holds totals in each row every order in shop. need count totals every single row grand total. how set query in laravel?

my orders table:

my orders table

my function:

   public function index() {          // orders in db         $orders = order::all();          // doesnt work, counts rows         $count_total = db::table('orders')->select('count(total)')->count();         dd($count_total);           // carts in db         $carts = cart::all();           return view('admin.pages.index', compact('orders', 'carts', 'count_products'));     } 

you can use eloquent way, doing can total sum of column.

$total = orders::sum('total'); echo "<pre>";   print_r($total); echo "<pre>"; 

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -