jesse_orange_newable's avatar

Unknown error when logging out

In my application I decided to make my own LogoutController as I didn't see the necessity of using Auth::routes


<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;

class LogoutController extends Controller
{
    /**
     * Logout and redirect to the login page
     *
     * @return void
     */
    public function logout(Request $request)
    {
        Auth::logout();

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

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

        return redirect()->route('login.ms');
    }
}

However, every time i try to actually log out i get the following error:

Illuminate\Contracts\Container\BindingResolutionException: Unresolvable dependency resolving [Parameter #0 [ $request ]] in class Illuminate\Http\Client\Request

I've never seen this error in my life and I'm certain it refers to something being added to the container but am unsure why this affects logging out specifically.

0 likes
3 replies
prasadchinwal5's avatar

@jesse_orange_newable Could you possibly replace these lines

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

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

with

Session::flush();

Not sure if this would help. But worth a shot.

jlrdw's avatar
jlrdw
Best Answer
Level 75

Also try changing:

public function logout(Request $request)
    

to

public function logout()

And you may need

use Illuminate\Support\Facades\Auth;

since you are using a static call to Auth (facade (__callstatic) )

jesse_orange_newable's avatar

To all who are interested, it turns out the Listener for my Logout event was using the wrong Request class,.

I had imported use Illuminate\Http\Client\Request;

When it fact it should have been use Illuminate\Http\Request;.

I solved this because you guys mentioned checking my facades, so I had a comb through literally everything and found this rather annoying issue.

Please or to participate in this conversation.