MohammadAbusaleh's avatar

Logout Won't Work, Laravel 5.2

Hey Guys,

New to laravel framework, and I was following the tutorial Laravel 5 Fundamentals.

Everything seems to work fine except logging out, whenever I go to localhost:8888/auth/logout

I get this error:

NotFoundHttpException in RouteCollection.php line 161:

and it won't get me logged out.

I'm using Laravel 5.2 and I have followed the tutorial step by step, so I assume something changed between 5 and 5.2 and I couldn't find the solution yet.

Thank you

0 likes
14 replies
bashy's avatar

5.2 doesn't come with the auth stuff (controllers/routes/views) by default. Have you run the php artisan make:auth command?

MohammadAbusaleh's avatar

I didn't run the command, but i copied them from a GitHub repository and placed them in: resources/views/auth

I got login, password, register and reset.

Should i remove these and use make:auth ?

MohammadAbusaleh's avatar
Route::group(['middleware' => ['web']], function () {
Route::get('about', 'PagesController@about');
    Route::get('contact', 'PagesController@contact');

    Route::resource('articles', 'ArticlesController');

    Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
    ]);

    Route::get('foo', ['middleware' => 'manager', function(){

    return 'this page may only be viewed by managers';
    }]);

});
masterpowers's avatar

try accessing the route at /logout if auth/logout wont work, it will work on /logout

MohammadAbusaleh's avatar

I tried that, it didn't work.

Full error:

in RouteCollection.php line 161 at RouteCollection->match(object(Request)) in Router.php line 802

at Router->findRoute(object(Request)) in Router.php line 670

at Router->dispatchToRoute(object(Request)) in Router.php line 654

at Router->dispatch(object(Request)) in Kernel.php line 246

at Kernel->Illuminate\Foundation\Http{closure}(object(Request))

at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139

at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 44

at CheckForMaintenanceMode->handle(object(Request), object(Closure))

at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124

at Pipeline->Illuminate\Pipeline{closure}(object(Request))

at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103

at Pipeline->then(object(Closure)) in Kernel.php line 132

at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99

bar2's avatar

since you are trying to work your way through Laravel, I think you can use the designated version of laravel within your scope of tutorials, right?

Here is how;

composer create-project laravel/laravel=5.1.* your-project-name --prefer-dist

or even better for your current situtation

composer create-project laravel/laravel=5.0.* learning-laravel-5 --prefer-dist

MohammadAbusaleh's avatar

Well, it's true I can do that, but since I'm planning to use Laravel for more than just a tutorial, since I really like the framework so far, I would prefer to get familiar with the latest version.

You're suggesting the easy way out, but eventually I'm gonna have to implement a logout for 5.2 in my website, one way or another.

JoshWilley's avatar
I didn't run the command, but i copied them from a GitHub repository and placed them in: resources/views/auth

I got login, password, register and reset.

Should i remove these and use make:auth ?

Yes, remove them and run the command. It's there for a reason.

MohammadAbusaleh's avatar

Thank you everyone.

Now the video didn't actually solve what's happening right now, but now I know where to start after the tutorial.

bashy's avatar

If you want to manually make that route, just do this

Route::get('logout', AuthController@getLogout);
public function getLogout() {
    auth()->logout();

    return redirect()->route('index');
}
3 likes
khaledSMQ's avatar

@MohammadAbusaleh @developernator @bashy

The problems come AuthController middleware since the default router name is " logout " and if you have change the name middleware will not recognized your router name.

You just need to keep the default name router OR fix your construct middleware

Route::get('logout', [ 'uses' => 'Auth\AuthController@getLogout', 'as' => 'logout' ]);


         /**
         * Create a new authentication controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware('guest', [ 'except' => 'logout' ]); // Default router name is "logout"
        }
1 like

Please or to participate in this conversation.