Laravel 8 speichern dynamisches Kontrollkästchen Ganzzahl -Wert -Array

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();
}
Selfish Skipper