lundi 1 mai 2017

Updating multiple rows on same page, Laravel 5.2

I'm displaying the entire contents of a DB table onto a single page in a similar format to what looks like an Excel spreadsheet.

I need to be able to save all the rows that the user has edited, my Controller function to handle the save is not quite right and I'm not sure whats the most efficient way to get this to work.

I think adding a loop inside of the function and adding a count, so that the 10 same input fields that belong to different ID's/Rows would save respectively.

Any help is greatly appreciated. Thanks.

Controller:

protected function CreateUpdateCompetitorRates(Request $request)

{
    $competitor_bluestone_rates_mrfs = Competitor_Bluestone_rates::where('id', $request->id)->first();

    $competitor_bluestone_rates_mrfs->id = $request->id;
    $competitor_bluestone_rates_mrfs->Portfolio = (empty($request->Portfolio)) ? '' : $request->Portfolio;
    $competitor_bluestone_rates_mrfs->Product_Type = (empty($request->Product_Type)) ? '' : $request->Product_Type;
    $competitor_bluestone_rates_mrfs->Doc_Type = (empty($request->Doc_Type)) ? '' : $request->Doc_Type;
    $competitor_bluestone_rates_mrfs->Product_Name = (empty($request->Product_Name)) ? '' : $request->Product_Name;
    $competitor_bluestone_rates_mrfs->LVR_Up_To = (empty($request->LVR_Up_To)) ? '' : $request->LVR_Up_To;
    $competitor_bluestone_rates_mrfs->Rate = (empty($request->Rate)) ? '' : $request->Rate;
    $competitor_bluestone_rates_mrfs->Mortgage_Risk_Fee = (empty($request->Mortgage_Risk_Fee)) ? '' : $request->Mortgage_Risk_Fee;

    $competitor_bluestone_rates_mrfs->save();

} 

View

        @foreach($competitor_la_trobe_rates_mrfs as $competitor_la_trobe_rates_mrf)
            <tr>
                                   <input type="text" value="" readonly>
                <input type="text" id="Portfolio_" value="">
                <input type="text" id="Product_Type_" value="Product_Type">
                <input type="text" id="Doc_Type_" value="">
                <input type="text" id="Product_Name_" value="">
                <input type="text" id="LVR_Up_To" value="">
                <input type="text" id="Rate_" value="">
                <input type="text" id="Mortgage_Risk_fee_" value="">


            </tr>
        @endforeach



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire