问题描述
我有两种类型的用户admin(默认用户表)和customer(我创建了customers表)。我使用了与laravel-jetstream一起提供的数据库驱动程序进行的会话。我的管理员身份验证没有问题。我正在成功获取管理员的用户信息。但是,当我与客户一起登录时,确实可以登录,但未获取任何已登录的客户信息。我已经检查了数据库。
auth.PHP
'guards' => [
'web' => [
'driver' => 'session','provider' => 'users',],'customer' => [
'driver' => 'session','provider' => 'customers','providers' => [
'users' => [
'driver' => 'eloquent','model' => App\Models\User::class,'customers' => [
'driver' => 'eloquent','model' => App\Models\Customer::class,
客户登录
public function login(Request $request) : object
{
if (Auth::guard('customer')->attempt($request->only('email','password'))) {
return redirect()->intended('/');
}else {
return back()->withErrors(['message' => 'Incorrect email or password']);
}
}
我的会话表如下所示
Schema::create('sessions',function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address',45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity')->index();
});
我了解 $ table-> foreignId('user_id')-> nullable()-> index(); 指向默认用户ID。 对于客户,如何存储客户ID并正确检索信息?
解决方法
我找到了答案。我犯了一个愚蠢的错误。
partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender,RoutedEventArgs e)
{
var button = this.Template.FindName("btnTest",this) as Button;
}
}
我想念守卫。