vendredi 10 avril 2020

insert data through checkbox in laravel

I am trying to insert the checkbox data in database in which data are coming dynamically from database, Here is the form :

<form action="" method="post" enctype="multipart/form-data">
                                @csrf()
                                @if(!empty($method)) @method($method) @endif
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">   
                                    @foreach($users as $k=>$u)
                                    <tr>
                                        <td><input type="checkbox" name="user_id[]" value=""></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    @endforeach
                                </table>
                                <input type="text" name="question_id[]" value="">
                                <input type="submit" class="btn btn-lg btn-success" value="Share" name="btn_btn_add_product">
                            </form>

Here is the controller :

$rs = ShareQuestion::create([
            'user_id' => $request->input('user_id'),
            'question_id' => $request->input('question_id')
        ]); 

        if($rs)
        {
          $message = array('flag'=>'alert-success', 'message'=>'Successfully');
          return redirect()->route('auth.question.index')->with(['message'=>$message]);
        }

        $message = array('flag'=>'alert-danger', 'message'=>'Please try again');
        return redirect()->route('auth.question.share')->with(['message'=>$message]);

Please help me out,




Aucun commentaire:

Enregistrer un commentaire