拉拉维尔 - 如何保存多行


Laravel - how to save multiple rows

我有这个存储方法:

    public function store(Requests'OfferRequest $request)
        {
    $start = $request->input('from'); // 04/24/2016 12:00 AM
    $end = $request->input('to); // 07/24/2016 12:00 AM
                $auction = new Auction($request->all());
                Auth::user()->auctions()->save($auction);
//how to get saved auction ID ?
    }

现在我需要在报价表中保存每天从 $start 到 $end 的空记录......只有我需要将保存的拍卖的ID放在报价表中的auction_id...

我可以将其保存在一个查询中还是需要使用 for 循环?最好的方法是什么?

请改用这种方式:

//how to get saved auction ID ?
$auction = new Auction();
$auction->fill($request->all());
$auction->user_id = 'Auth::user()->id;
$auction->save();
$auction_id = $auction->id;
$dStart = new DateTime($start);
$dEnd   = new DateTime($to);
// Will loop through everyday from $dStart to $dEnd
while ($dStart < $dEnd) {        
    // current date of the loop formated for db use
    $date = $dStart->format('Y-m-d');
    // Code to insert date to Offer 

    $dStart->add(new DateInterval("P1D"));
}