0

Here I have code that store my $auction into auction database:

public function store(Requests\OfferRequest $request)
    {

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

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

Now I from request get $from and $to fields:

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

Now I want to store into maxoffers database - rows, foreach date between 'from' and 'to' and this rows just to have auction_id = $auction->id; and price = $auction->price ... other fields to be empty...

How I can do that? So how to make foreach date between from and to and store id of auction and price from request...

3
  • Can I see your database structure? Commented Apr 22, 2016 at 13:45
  • i.imgur.com/PqEHQl2.png Commented Apr 22, 2016 at 14:10
  • @Andrew did you try my answer ? Commented Apr 23, 2016 at 9:22

1 Answer 1

2

It is quite simple.

$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();
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.