vendredi 13 mars 2020

update multiple rows in a table against an id

I want to update multiple rows in a table, I tried a lot but could not do that. I see different thread to find solution but not find. Here is below I share my controller code, edit blade code.

Here is Controller code: the Second part of this Code is not update the records from this line $c=count($data['customer']);;

public function update(Request $request)
{
    $data = $request->all();

    $empid = Session::get('emp_id');
    $empname = Session::get('user_name');


    $id = $data['id'];
    $exhibition_type = $data['exhibition_type'];
    // $trndate = $data['trndate'];
    $season = $data['season'];
    $meeting_date = $data['meeting_date'];
    $update_exhibition = DB::update("update EXHIBITION_FABRIC_HEADERS set  EXHB_TYPE_ID='$exhibition_type', SEASON_ID = '$season', MEETING_DATE ='$meeting_date', LAST_UPDATE_BY ='$empid', LAST_UPDATE_BY_NAME = '$empname' where trnno = '$id'");

    $c=count($data['customer']);
    for ($i=0;$i<$c;$i++) {
    $customer = $data['customer'][$i];
    dd($customer);
    $category = $data['category'][$i];
    $fabric_code = $data['fabric_code'][$i];
    $selection = $data['selection'][$i];

    $update_exhibition = DB::update("update EXHIBITION_FABRIC_LINES set CUSTOMER_ID = '$customer', FABRIC_CATEGORY_ID='$category', FABRIC_CODE = '$fabric_code', SELECTION_FLAG ='$selection', LAST_UPDATE_BY ='$empid', LAST_UPDATE_BY_NAME = '$empname' where trnno = '$id'");        
    }

    if ($update_exhibition == true)
    {
        return response()->json(['result' => 'success', 'trnno' => $id]);

    }
    else
    {
        return response()->json(['result' => 'error']);
    }
} 

Here is The edit.blade.php:

<form method="post" name="exhibition_form" id="exhibition_form" action="">
                            

                        <div class="row">
                             <input type="hidden" name="id" id='id' value="">
                                <!-- @php
                                $max = DB::select("select  nvl(max(TRNNO),0)+1 ID from EXHIBITION_FABRIC_HEADERS");
                                $trnno = $max[0]->id;
                                $trn_date = date('Y-m-d');
                                @endphp -->

                                <div class="col-md-2 form-group mb-3">
                                    <label for="doc">Doc #</label>
                                    <input type="number" class="form-control" id="doc" name="doc" value="" placeholder="Doc #" readonly="true">
                                </div>

                                <div class="col-md-2 form-group mb-3">
                                    <label for="doc">Doc Date</label>
                                    <input type="text" class="form-control" id="trn_date" name="trn_date" value="" placeholder="Doc Date" readonly="true">
                                </div>

                                <div class="col-md-2 form-group mb-3">
                                    <label for="exhibition_type">Exhibition Type</label>
                                    <select class="form-control" name="exhibition_type" id='exhibition_type'>
                                        <option value="">Select Exhibition Type</option>
                                        @foreach($exhibition_type as $exhibition)
                                        <option value="" <?php if($exhibition->exhb_type_id==$exhibition_headers[0]->exhb_type_id){ echo 'selected';} ?>></option>
                                        @endforeach

                                    </select>
                                </div>

                                <div class="col-md-2 form-group mb-3">
                                    <label for="season">Season</label>
                                    <select class="form-control" name="season" id='season'>
                                        <option value="">Select Season</option>
                                        @foreach($season as $sea)
                                        <option value="" <?php if($sea->season_id==$exhibition_headers[0]->season_id){ echo 'selected';} ?>></option>
                                        @endforeach

                                    </select>
                                </div>

                                <div class="col-md-3 form-group mb-3">
                                    <label for="meeting_date">Meeting Date</label>
                                    <input type="date" class="form-control" id="meeting_date" name="meeting_date" placeholder="Enter Meeting Date" value="">
                                </div>
                            </div>

                            <div class="row">

                              @foreach($exhibition_lines as $key => $exhibition_line)

                                <div class="col-md-3 form-group mb-3">
                                    <label for="customer">Customer</label>
                                    <select class="form-control" name="customer[]" id='customer'>
                                        <option value="">Select Customer</option>
                                        @foreach($customers as $customer)
                                        <option value="" <?php if($customer->customer_id==$exhibition_lines[$key]->customer_id){ echo 'selected';} ?> ></option>
                                        @endforeach

                                    </select>
                                </div>

                                <div class="col-md-3 form-group mb-3">
                                    <label for="category">Category</label>
                                    <select class="form-control" name="category[]" id='category'>
                                        <option value="">Select Category</option>
                                        @foreach($categories as $category)
                                        <option value="" <?php if($category->fabric_category_id==$exhibition_lines[$key]->fabric_category_id){ echo 'selected';} ?> ></option>
                                        @endforeach

                                    </select>
                                </div>

                                <div class="col-md-3 form-group mb-3">
                                    <label for="fabric_code">Fabric Code</label>
                                    <select class="form-control" name="fabric_code[]" id='fabric_code'>
                                        <option value="">Select Fabric Code</option>
                                        @foreach($fabric_codes as $fabric_code)
                                        <option value="" <?php if($fabric_code->fabric_code==$exhibition_lines[$key]->fabric_code){ echo 'selected';} ?> ></option>
                                        @endforeach

                                    </select>
                                </div>

                                <div class="col-md-1 form-group mb-1">
                                    <label for="selection">Selection</label>
                                    <input type="hidden" name="selection[]" id="selection_0" value="off">
                                    <input type="checkbox" class="form-control re_selection"  data-id='0'   id="re_selection_0" name="re_selection[]" onclick="get_selection('0')" <?php if($exhibition_lines[0]->selection_flag == 'on'){ echo 'checked'; } ?> >
                                </div>

                                <div class="col-md-1 form-group mb-1">
                                    <br>
                                    <a style="padding: 4px;color:#fff" class="btn btn-success btn-sm" type="button" onclick="add_more();"><i class="text-18  i-Add"></i></a>
                                    <a style="padding: 4px;color:#fff" class="btn btn-danger btn-sm" type="button" onclick="remove_row();"><i class="text-18  i-Remove"></i></a>
                                </div>
                        @endforeach
                            </div>

                            <div id="add_here"></div>

                            <div class="col-md-2 form-group mb-3">
                                    <label></label>
                                    <a class="btn btn-success" id="submit" onclick="exhibition_update();">Save</a> 
                                    <!-- <input type="submit"> -->
                            </div>
                        </form> 

Here is the route.php:

Route::post('/update_exhibition', 'ExhibitionController@update')->name('update_exhibition')- 
>middleware('checksession');

Here i will share my edit form screenshot below

enter image description here

please tell me the solution of this problem where i can make a mistake. Thanks in Advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire