laravel 8 storing dynamic checkbox integer value array

70

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


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

Comments

Submit
0 Comments