0

I have the table with each row containing checkbox where checkbox value is set as id from the database. How can i access them to controller to update in database. I have tried to dump the value in my controller but it show NULL. Here is my view:

<form  action= "po" method="POST" >
 @csrf

 <input type="submit" name="submit">
      <div class="table-responsive">

        <table class="table custom-table">
          <thead>
            <tr>
              <th scope="col">
                <label class="control control--checkbox">
                  <input type="checkbox" class="js-check-all"/>
                  <div class="control__indicator"></div>
                </label>
              </th>
              <th scope="col" >S.N</th>
              <th scope="col">LC NO</th>
              <th scope="col">Applicant</th>
              <th scope="col">Doc Value</th>
              <th scope="col">Doc Received date</th>
              <th scope="col">LC Type</th>
              <th scope="col">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php $number = 1;?>
            @foreach($datas as $items)
              
            <tr>
              <th scope="row" style="padding:20px">
                <label class="control control--checkbox">
                  <input type="checkbox" name="checkboxlist[]" value="{{$items->id}}" />
                  <div class="control__indicator"></div>
                </label>
              </th>
              <td>{{$number}}</td>
              <td>{{$items->lc_no}}</td>
              <td>{{$items->applicant}}</td>
              <td>{{$items->doc_value}}</td>
              <td>{{$items->rec_date}}</td>
              <td>{{$items->sight_usance}}</td>
            </tr>
            <?php $number++; ?>
            @endforeach
         
            
          </tbody>
        </table>
      </div>
      </form>

Here is my Controller

 function po(Request $req){

        dd($req->chekboxlist);


    }
4
  • have you checked checkbox or else it return null.To avoid that you need to add validation Commented Jun 15, 2021 at 14:30
  • Ya i checked chekbox...And how can i add validation... Commented Jun 15, 2021 at 14:40
  • is it still returning null after clicking checkbox Commented Jun 15, 2021 at 14:46
  • Yes!! @JohnLobo still returning null Commented Jun 15, 2021 at 14:51

1 Answer 1

1

You are accessing wrong key from Request $req->chekboxlist

But it should be

$req->checkboxlist

Always add Validation to Avoid erorrs while saving data

 $validate=Validator::make($request->all(), [
            "checkboxlist"    => "required|array",
           

        ]);
if($validate->fails()){
  return redirect()->back()->with("errors",$validate->errors());
}
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.