0
votes

Im trying to get client IP through controller named LoginController but the error still there.

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

I've follow this SO question but still get the same error.


LoginController.php
namespace App\Http\Controllers\Auth;

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

class LoginController extends Controller
{
     /**
     * The user has been authenticated.
     *
     * @param  App\Http\Controllers\Auth\Request $request
     * @param  mixed  $user
     * 
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        $user->update([
            'last_login_at' => Carbon::now()->toDateTimeString(),
            'last_login_ip' => $request->getClientIp()
        ]);

        if($user->isAdmin === 1) {
            return redirect()->intended('admin');
        }
    }
}


EDITED

So, I just found out about AuthenticatesUsers.php which is a trait(?) and found this code. Should I edit this code or not?

/**
 * The user has been authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  mixed  $user
 * @return mixed
 */
 protected function authenticated(Request $request, $user)
 {
    //
 }
1
It is not clear what you are asking. How have you followed the answer given in the link you provide? - Jon Guiton
@JonGuiton I had change the use App\Http\Controllers\Auth\Request to use Illuminate\Http\Request but still getting the same error so I thought the solution is not working. I must have been missed something. Anyway, the question had been answered with the same answer as that SO answer. :shakehead: My bad. - Qrazier

1 Answers

0
votes

Change your use statement:

use Illuminate\Http\Request;
// Instead of
use App\Http\Controllers\Auth\Request;

You're overriding this method from the AuthenticatesUsers trait, which receives a Illuminate\Http\Request, not a App\Http\Controllers\Auth\Request