实例已给出,仍在控制器中检测到其他实例 [英] Instance have been given, still detect other instance in controllers
问题描述
我正在尝试通过名为LoginController的控制器获取客户端IP,但错误仍然存在.
Im trying to get client IP through controller named LoginController but the error still there.
传递给App \ Http \ Controllers \ Auth \ LoginController :: authenticated()的参数1必须是App \ Http \ Controllers \ Auth \ Request的实例,Illuminate \ Http \ Request的实例已给出
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');
}
}
}
已编辑
因此,我刚刚发现了AuthenticatesUsers.php,它是一个特征(?),并找到了此代码.我是否应该编辑此代码?
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)
{
//
}
推荐答案
更改您的use
语句:
use Illuminate\Http\Request;
// Instead of
use App\Http\Controllers\Auth\Request;
您正在覆盖此AuthenticatesUsers
特征中的方法,该特征将接收Illuminate\Http\Request
,而不是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
这篇关于实例已给出,仍在控制器中检测到其他实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!