1

I am new in Laravel and using Laravel 5.6. I want to edit that where the user will be redirected after logout. So I checked the web.php file and then by going in CMD I typed php artisan route:list all routes came up, there is a POST method of logout and its controller is App\Http\Controllers\Auth\LoginController@logout so I checked the LoginController there is nothing except following code, where is the logout method???

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

I have also searched, what I found is to change the $redirectTo variable's value but it's not woking because it's the URL after login.

1 Answers1

3

The logout function is inside

use AuthenticatesUsers;

It looks like so

/**
 * Log the user out of the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function logout(Request $request)
{
    $this->guard()->logout();

    $request->session()->invalidate();

    return redirect('/');
}

The redirectTo is used by the AuthenticatesUsers; trait

use RedirectsUsers

Which looks like

public function redirectPath()
{
    if (method_exists($this, 'redirectTo')) {
        return $this->redirectTo();
    }

    return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}

The routes for auth comes from the

Auth::routes();

in web.php

Marcus
  • 1,850
  • 1
  • 12
  • 24
  • I have solved this I have one more question, it takes 90 mint to post 1 more so can u help a little bit??? –  Aug 09 '18 at 06:03
  • 1
    sure, what is the problem? – Marcus Aug 09 '18 at 06:16
  • I am getting an error that when the user is *logged out* it must not show the Homepage which is Authenticated, but after logging out **when I press the back button** *it shows the home page*, but after refresh it shows Login form, I want that if anyone presses the back button it must not show the homepage, and if I **logout again** from the homepage which *came up by pressing back button* it shows **"The page has expired due to inactivity. Please refresh and try again."** –  Aug 09 '18 at 06:41
  • 1
    The problem is that the browser usually does not reload the page when using the back button, because it caches it. Why is it a problem though, the logged out user wont be able to get any new information from the system in the home view – Marcus Aug 09 '18 at 06:49
  • 1
    Well sure if it really is a problem you might be able to solve it with some javascript that checks if the user i logged in and forces the page to reload. Or read https://stackoverflow.com/questions/31735428/prevent-browser-back-button-cache – Marcus Aug 09 '18 at 07:11
  • 1
    No problem (y). – Marcus Aug 09 '18 at 07:46