Delete function kills session in Laravel 5.5

Asked

Viewed 194 times

1

When deleting a selected user, other than the currently logged in user, the function modeloReferenciadoPorObjeto->delete() of Laravel is terminating the logged-in user session.

public function deletar($id)
{
    $usuarioRecuperado = $this->user->find($id);
    //aqui consigo selecionar o usuário que desejo deletar tranquilamente
    $deletarUsuario = $usuarioRecuperado->delete();
    return view('painel.home.user.index');
}

In the project was used the auth which is already in the Laravel, generated from your command.

The only thing altered was Auth\RegisterController. In the constructor method it has been modified to the $this->middleware('auth');.

So if you start from the premise that you can only register if you are logged in to the system.

  • Auth::logout(); doesn’t solve your problem?

1 answer

0

The problem that was happening is that the function register() in class RegisterUser when registering a user it was automatically logged in to the system, and I always registered and tried to delete. The user session was updated for that user who had just registered, when the function was called delete() then deleted the logged-in user and not the others so I just changed it so it doesn’t happen in the function register()

public function register(Request $request)
  {
     $usuarios = User::all();
     $this->validator($request->all())->validate();

     event(new Registered($user = $this->create($request->all())));

    // $this->guard()->login($user);

     //return $this->registered($request, $user)
                    //?: redirect($this->redirectPath());

     //depois disso apenas compactei o usuário atual da sessão e enviei para a view
     return view('painel.home.user.index', compact("usuarios"));
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.