Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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

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
Php 以天为单位,以月为单位,以年为单位,在拉雷维尔进行报告_Php_Laravel - Fatal编程技术网

Php 以天为单位,以月为单位,以年为单位,在拉雷维尔进行报告

Php 以天为单位,以月为单位,以年为单位,在拉雷维尔进行报告,php,laravel,Php,Laravel,我的代码和产品,数量和价格,但我需要3个功能,为天,年,月,在第一,我会得到总的产品在每一天,下一个月,最后在每年 代码 $product_orders = \App\OrderProduct::select(DB::raw('sum(line_total) as total_line'), DB::raw('sum(qty) as qty') , 'product_id','line_total','created_at')-> orderBy('created_at')->gro

我的代码和产品,数量和价格,但我需要3个功能,为天,年,月,在第一,我会得到总的产品在每一天,下一个月,最后在每年

代码

$product_orders = \App\OrderProduct::select(DB::raw('sum(line_total) as total_line'),
DB::raw('sum(qty) as qty') , 'product_id','line_total','created_at')->
orderBy('created_at')->groupBy('product_id')->get();

分贝

试试这个,让我知道发生了什么

试试这个:

$Rspatients = DB::table('reports')
->select(
    DB::raw("day(created_at) as day"),
    DB::raw("Count(*) as total_patients"))

->orderBy("created_at")
->groupBy(DB::raw("day(created_at)"))
->get();


$result_patients[] = ['day','Patients'];
foreach ($Rspatients as $key => $value) {
$result_patients[++$key] = [$value->day,$value->total_patients];
}
然后可以将其传递到视图,如下所示:

return 
view('Dashboard.index')
        ->with('result_patients',json_encode($result_patients));

我使用谷歌图表,这就是为什么我将数据作为json发送到视图,然后将数据馈送到谷歌图表的折线图。

今年有产品未返回示例只有2个产品返回,您可以再次检查吗请发布您的数据库表,以便我可以确保。。。我想答案是可以的,我是指数据。。。。我想显示所有行…为什么不显示数据通过在每个组中添加rpdocut\u id解决了此问题请更新您的答案,以了解我的答案对您的帮助
$Rspatients = DB::table('reports')
->select(
    DB::raw("day(created_at) as day"),
    DB::raw("Count(*) as total_patients"))

->orderBy("created_at")
->groupBy(DB::raw("day(created_at)"))
->get();


$result_patients[] = ['day','Patients'];
foreach ($Rspatients as $key => $value) {
$result_patients[++$key] = [$value->day,$value->total_patients];
}
return 
view('Dashboard.index')
        ->with('result_patients',json_encode($result_patients));