Laravel 5 Redirect After logging out - how to redirect back?

I want to redirect back to where the user was after he logged out successfully, because I have methods that are available even when logging out.

I protect every method in PhotosController except @show

public function __construct()
{
    $this->middleware('auth', ['except' => 'show']);
}

To set the redirection after logging out, I set the property in my AuthController as follows:

protected $redirectAfterLogout = '/customLogoutPage';

But I want to redirect the user back to where he was, since he can see the view even without blocking.

I tried something in this direction:

protected $redirectAfterLogout = redirect()->back();

But my browser says: "Unexpected" (', waiting', 'or'; '

, , .

+4
2

logout- , . , AuthController.

, :

public function getLogout()
{
    Auth::logout();

    return redirect()->back();
}

.

, , Laravels AuthenticatesUser:

/**
 * Log the user out of the application.
 *
 * @return \Illuminate\Http\Response
 */
public function getLogout()
{
    Auth::logout();

    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
+1
public function getLogout()
{
    Auth::logout();

    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/customLogoutPage');
}
+1

Source: https://habr.com/ru/post/1612184/


All Articles