0

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)
 {
    //
 }
Qrazier
  • 162
  • 4
  • 15
  • It is not clear what you are asking. How have you followed the answer given in the link you provide? – Jon Guiton May 13 '19 at 17:50
  • @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 May 13 '19 at 18:07

1 Answers1

0

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

SystemGlitch
  • 2,150
  • 12
  • 27
  • Ahh.., but the error said `must be an instance of App\Http\Controllers\Auth\Request`. I thought the function needs to use that request. Thanks for you help! – Qrazier May 13 '19 at 17:46
  • @Qrazier It said that because you defined the method with a parameter of type `App\Http\Controllers\Auth\Request` but Laravel still passes a `Illuminate\Http\Request` to it. – SystemGlitch May 14 '19 at 08:35