Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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每隔一周显示一次总价?_Laravel - Fatal编程技术网

如何在Laravel每隔一周显示一次总价?

如何在Laravel每隔一周显示一次总价?,laravel,Laravel,我在拉威尔学算术。我想分别显示第一周、第二周、第三周和第四周的“总价”。我还显示了这个月的总价 你能教我怎么写控制器代码吗 public function total_price_amount_this_month() { $prices= PriceList::orderBy('id', 'desc')->get(); return view('total_price_amount_this_month',compact('prices'));

我在拉威尔学算术。我想分别显示第一周、第二周、第三周和第四周的“总价”。我还显示了这个月的总价

你能教我怎么写控制器代码吗

public function total_price_amount_this_month()
    {
        $prices= PriceList::orderBy('id', 'desc')->get();
        return view('total_price_amount_this_month',compact('prices'));
    }

    public function the_first_week()
    {
        $prices= PriceList::orderBy('id', 'desc')->get();
        return view('the_first_week',compact('prices'));
    }
这是我的桌子


如果您想计算最近7天的总价,可以这样做:

$price = PriceList::whereDate('time', Carbon::now()->subDays(7))
                   ->sum('price');
print_r($price);
或者,如果要手动输入日期,请使用
whereBetween()

希望它能帮助你

编辑:如果需要手动编辑

$from_date = //Whatever
$to_date = //Whatever
$price = PriceList::whereBetween('time', [$from_date, $to_date])
                   ->sum('price');


这就是你必须做的

谢谢你的回答。我懂了。。。我必须手动选择日期。。。有没有办法打开_first_week.blade.php页面并显示总价格?首先选择日期(如果通过输入手动),然后计算价格总和,并用该值重定向到所需的blade中。谢谢评论。你能教我密码吗?第二周,即2020年5月3日至2020年5月9日,情况如何?