這是我的控制器功能爲什麼laravel查看返回數組?而不是價值?
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'));
}
這是我的視圖
<div class="panel-body">
<h2>{{$totalsales}}</h2>
insted的值本身的視圖的返回這樣
[{"totalsales":"130.00"}]
使用get(),您將得到收集 –
@SagarGautam - >等什麼我前人的精力呢? –
如果你只需要記錄,你可以使用' - > first()',否則使用' - > get()'。在上面的例子中,你可以在'$ totalsales'上使用foreach。 –