mardi 24 avril 2018

Store dynamically created checkbox value in another table in Laravel

I have the following code to dynamically generate check-boxes from one table:

{!! Form::open(['url' =>URL::to('admin/user/'.$profileUser->id) , 'method'=>'PUT', 'enctype'=>'multipart/form-data' ]) !!}
                    @foreach ($userRoles as $key => $userRole)
                    <tr>
                        <td width="10%"></td>
                        <td></td>
                    </tr>
                    @endforeach
                    <tr></tr>
            </tbody>
            

In the controller I have:

    if (isset($_POST['roleSubmit'])){
        DB::table('role_users')->where('user_id', $request->get('id', $id))->delete();


        $userRole = json_encode($request->input('rolename'));
        DB::table('role_users')->insert(
            array(
                'user_id' => $id,
                'role_id' => $userRole
            )
        );
        return redirect()->back();
    }

I need to dynamically generate multiple checkboxes from 'roles' tableenter image description here

and display like this: enter image description here

Then I need to store the checkbox values in 'role_users' like this:enter image description here

Instead, for the above snippet of code, I am getting this: enter image description here

Any guideline where I am messing it?




Aucun commentaire:

Enregistrer un commentaire