2016-04-22 4 views
0
私は $auctionオークションデータベースに保存し、コードを持っている。ここ

間の行foreachの日付を追加私はmaxoffersデータベースに格納する - 行、 'from'と 'to'の間のforeach日付とこの行はちょうどauction_id = $auction->id;price = $auction->priceを持っている...他のフィールドは空...Laravel日付

どうすればいいですか?だからforeach日付をfromtoの間にする方法とオークションのストアIDとリクエストからの価格...

+0

データベースの構造は確認できますか? – Siddharth

+0

http://i.imgur.com/PqEHQl2.png – Andrew

+0

@Andrewあなたは私の答えを試しましたか? – nextt1

答えて

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(); 
    }