ken4ward's avatar

Save new model record in the db

I am trying to save this record but it keeps returning the page without actually performing the saving. No error message is sent as response and the chrome debug console gives no idea as to what s going on, so I'm left to guess and your professional advice on how to solve this riddle.

This is the function to perform the actual saving in the DB.

public function returnObjects(BidWinnerRequest $bidWinnerRequest){
        $product_id                             = $bidWinnerRequest->product_id;
        $bidding_table_id                       = $bidWinnerRequest->bidding_table_id;

        if($bidWinnerRequest->isMethod('post')){
            $bidWinner = new BidWinner;
            $bidWinner->product_id       = $product_id;
            $bidWinner->bidding_table_id = $bidding_table_id;

            $bidWinner->actual_price                = floatval(4567);
            $bidWinner->offered_price_price         = floatval(112233);;

            $bidWinner->save();
            return redirect()->route('biddingCommentView')->with('message', 'Your question has been posted.');
        }
    }

This is the function returning the page, appended are the models that matches the query. To each model a button is attached, so depending on the button selected the corresponding model is returned.

public function show($id)
    {
        $biddingComments = BiddingComments::findOrFail($id);
        return view('buyers.show')->with('biddingComments', $biddingComments);
    }

This is the page This is the route I'm using for the posting

Route::post('post/to/input/save', array('before'=>'csrf', 'uses'=>'MyBuyers@returnObjects'));

This is the page that displays the selected model. This is the page I will make a selection from. It is from this I want to save the records into the database.

{!! Form::open(array('url' => 'post/to/input/save', 'method' => 'post')) !!}
    {!! Form::token() !!}

                <div align="center" background-color="white"><TABLE>
                      <TH>FIELDS</TH><TH>NAMES</TH>
                      <TR><TD><B>PRICE </B></TD><TD>{!! $biddingComments->price !!} (US Dollars)</TD></TR>
                      <TR><TD><B>DOCUMENTS TO UPLOAD</B></TD><TD>{!! $biddingComments->documentPerSector !!}</TD></TR>
                      <TR><TD><B>PAYMENT METHOD</B></TD><TD>{!! $biddingComments->payment_methods !!}</TD></TR>          
                      {!! Form::hidden('bidding_table_id', $biddingComments->id) !!}
                      {!! Form::hidden('product_id', $biddingComments->product_id) !!}
                      <TR><TD><B>{!! Form::submit('SUBMIT') !!}</B></TD><TD></TD></TR>

                </TABLE>
            </div>
  @stop
0 likes
2 replies
ahuggins's avatar

Where are your input fields in the form? In the last snippet of code, I don't see any inputs except for the hidden ones. This makes me think there is no data making it to your save method.

I would do this:

public function returnObjects(BidWinnerRequest $bidWinnerRequest){
    dd($bidWinnerRequest);
        $product_id                             = $bidWinnerRequest->product_id;
        $bidding_table_id                       = $bidWinnerRequest->bidding_table_id;

        if($bidWinnerRequest->isMethod('post')){
            $bidWinner = new BidWinner;
            $bidWinner->product_id       = $product_id;
            $bidWinner->bidding_table_id = $bidding_table_id;

            $bidWinner->actual_price                = floatval(4567);
            $bidWinner->offered_price_price         = floatval(112233);;

            $bidWinner->save();
            return redirect()->route('biddingCommentView')->with('message', 'Your question has been posted.');
        }
    }

Then try to submit the form again and see what is in your request object: dd($bidWinnerRequest);

If there is no data, then that is the problem.

jlrdw's avatar

Have you taken the 2 tutorials built right into the documentation to learn how to do this stuff?

Please or to participate in this conversation.