Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Zaheer's avatar

Error on Authenticated User Login

I am trying to define a Global Session Variable in Login Controller of Laravel 6.

protected function authenticated(Request $request, $user)
{
    $branch_id = auth()->user()->branch_id;
    session()->put('lbranch', $branch_id);
    if ($branch_id==0){
        $branchid = Branch::first('id');
        session()->put('lbranch', $branchid->id);
    }
}

But I am getting the following error :

Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in E:\ZAH\Laravel\myaccounts\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php on line 111

When I change :

use App\Http\Controllers\Auth\Request;

with

use Illuminate\Http\Request;

everything works fine. My question is what is the proper way of using authenticated function with Auth request.

0 likes
2 replies
Nakov's avatar

Yes, this should be the correct import:

use Illuminate\Http\Request;

If you don't do that, it tries to find the Request within the Auth directory, where it does not exists.

And then instead of this :

$branch_id = auth()->user()->branch_id;

You can also just use this:

$branch_id = $user->branch_id;

As the $user in the list is the already signed one.

munazzil's avatar

The above one is all request related and you can use below one for specifically for auth user only,

        use Auth;

Please or to participate in this conversation.