Laravel错误-调用未定义的方法Illumb\Database\Query\Builder::gets()
我正在Laravel中运行查询,但出现以下错误: 调用未定义的方法Illumb\Database\Query\Builder::gets() 我已经写了这个问题 控制器Laravel错误-调用未定义的方法Illumb\Database\Query\Builder::gets(),laravel,Laravel,我正在Laravel中运行查询,但出现以下错误: 调用未定义的方法Illumb\Database\Query\Builder::gets() 我已经写了这个问题 控制器 $currentMonth = date('m'); $currentmonthbilling = DB::table("billings") ->select(DB::raw("SUM(amount) as total"))
$currentMonth = date('m');
$currentmonthbilling = DB::table("billings")
->select(DB::raw("SUM(amount) as total"))
->whereRaw('MONTH(created_at) = ?',$currentMonth)
->gets();
看法
{{$currentmonthbilling[0]>total}
我希望它显示当月的总金额是->get()代码>非->get()代码>
如前所述,您应该使用get()
而不是get()
但是您根本不需要get()
,而且可以写得更清楚
$total = DB::table('billings')
->whereMonth('created_at', date('m'))
->sum('amount');
->get()
应该是->get()
而且我认为您应该在这里使用->first()
,因为您需要查找单个值。在视图中,只需使用as{{$currentmonthbilling->total}
$currentmonthbilling = DB::table("billings")
->select(DB::raw("SUM(amount) as total"))
->whereRaw('MONTH(created_at) = ?',$currentMonth)
->get();`
$total = DB::table('billings')
->whereMonth('created_at', date('m'))
->sum('amount');