Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel错误-调用未定义的方法Illumb\Database\Query\Builder::gets()_Laravel - Fatal编程技术网

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"))

我正在Laravel中运行查询,但出现以下错误:

调用未定义的方法Illumb\Database\Query\Builder::gets()

我已经写了这个问题

控制器

            $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');