这里我有将我的$auction
存储到拍卖数据库中的代码:
public function store(Requests\OfferRequest $request)
{
$auction= new Auction($request->all());
Auth::user()->auctions()->save($auction);
}
现在我从请求获取$ from和$ to fields:
$auction->from //return me start date for auction
$auction->to // return me end date for auction
现在我想存储到maxoffers
个数据库 - 行,日期为' from
'和' to
'这行只是为了auction_id = $auction->id;
和price = $auction->price
...其他字段为空...
我怎么能这样做?那么如何让foreach日期在from
和to
之间,以及拍卖的商店ID和来自请求的价格......
答案 0 :(得分:1)
这很简单。
$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();
}