samedi 1 avril 2017

Laravel 5.4 detach row

When i want change password user and user table got relationship i made detch, next i can change password but how use attach to add again thats same role what user got?

Route::post('profil/changepassword', function() {
    $User = User::find(Auth::user()->id);
    //$User->roles()->$rola;
    $User->roles()->detach();
if(Hash::check(Input::get('passwordold'), $User['password']) && Input::get('password') == Input::get('password_confirmation')){
        $User->password = bcrypt(Input::get('password'));
        $User->save();
        $User->roles()->attach(1);
        return back()->with('success','Hasło zostało zmienione');
    } 
     else{
        return back()->with('error','Hasło nie zostało zmienione');
    }
});

I made something like that and when user change password it will get role User. When Moderator change password thats same get User role not moderator like got befor. So i ask how i can figure it becouse i will use detach in other funcion and i really dont know how make it.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire