我面临一个独特的问题,我的数据库中只有 3 个用户数据 John、Cindy 和 Carla,我使用用户名 john 登录,但我得到 Carla 的身份验证数据,它应该是 john 的身份验证数据。
这是我的登录功能LoginController.php
public function login(Request $request) {
$this->validateLogin($request);
$credentials = ['user_id' => \Arr::get('user_id','', $request->input('user_id')),
'password' => \Arr::get('password','', $request->input('user_password'))
];
if(Auth::attempt($credentials)){
return redirect()->intended($this->redirectPath());
}
return back()->withInput($request->except('password'))->withErrors(['Username atau Password Wrong! ']);
}
Run Code Online (Sandbox Code Playgroud)
这是我的用户模型
class User extends Authenticatable {
use Notifiable;
use HasRoles;
protected $table = "m_user";
protected $primaryKey = "user_id";
public function getAuthPassword() {
return $this->hash_password;
}
protected $fillable = [
'user_id', 'nama', 'user_password','hash_password','role', 'company','is_active','created_by','created_at','updated_by','updated_at'
];
protected $hidden = [
'password', 'remember_token',
];
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我在我得到的约翰用户数据
dd(Auth()->user())之后 放置时,这是正确的,但是如果我在我的应用程序中,我会得到卡拉身份验证数据。为什么?Auth::attempt()dd(Auth()->user())another Controller
仅供参考:卡拉是我的用户表中的第一行数据。
if(Auth::attempt($credentials)) {
dd(auth()->user()); <---- here, i get John Auth Data
return redirect()->intended($this->redirectPath());
}
Run Code Online (Sandbox Code Playgroud)
尝试在另一个控制器中添加。但获取卡拉授权数据。
class DashboardController extends Controller {
public function overview() {
dd(auth()->user()); <---- i get Carla Auth Data, it's supposed to John Auth data.
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,为什么
Auth::user() or auth()->user()不在另一个控制器中返回登录用户的数据呢?