繁体   English   中英

Laravel-在日期之间添加行foreach日期

[英]Laravel - add row foreach date between dates

在这里,我有将$auction存储到拍卖数据库中的代码:

public function store(Requests\OfferRequest $request)
    {

            $auction= new Auction($request->all());

            Auth::user()->auctions()->save($auction);
}

现在我从请求中获取$ from和$ to字段:

$auction->from //return me start date for auction
$auction->to // return me end date for auction

现在,我想存储到maxoffers数据库中-行,foreach日期在' from '和' to '之间,并且此行仅具有auction_id = $auction->id; and price = $auction->price ...其他字段为空...

我该怎么做? 因此,如何使foreach日期介于fromto之间to并存储拍卖ID和请求中的价格...

这很简单。

$start_date = \Carbon\Carbon::parse($auction->from);
$end_date = \Carbon\Carbon::parse($auction->to);


    while(!$start_date->eq($end_date))
    {
        $temp = new maxoffers;
        $temp->id = $auction->id;
        $temp->price = $auction->price;

        //$temp->something_else = 'value';
        //If Your structure does not support null values then you must define some values here.

        $temp->save()

        $start_date->addDay();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM