Here is my controller function
public function index()
{
$currentdate = Carbon::yesterday();
$totalsales = DB::table('receipts')
->whereDate('created_at','=', $currentdate)
->where('status','=', 'served')
->orderBy('created_at','asc')
->select(DB::raw('SUM(amount_due) as totalsales'))
->get();
// ->first();
// return $totalsales;
return view('dashboard.index',compact('totalsales'));
}
Here is my View
<div class="panel-body">
<h2>{{$totalsales}}</h2>
insted of the value itself the view returns an array like this
[{"totalsales":"130.00"}]
->first()on otherwise use->get(). In above case you can use foreach on$totalsales.