Laravel 5.6 身份验证 - 不标准 table
Laravel 5.6 auth - not standard table
我对 Laravel 很陌生,在使用 auth 选项时遇到了一些问题。
我正在尝试在另一个自定义 table 上使用身份验证。我已经设置了与新 table 的连接,但是 Laravel 仍在搜索电子邮件字段。在我的 table 中有 'login' 字段。我不知道在哪里更改它,有人可以帮忙吗?
我正在使用 Laravel 5.6
我创建了新模型并将受保护的 $table
添加到 User(默认)模型。
那是我的错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause'
您可以覆盖文件 vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
中的任何函数。在您的情况下,您只需将其添加到 app/Http/Controllers/Auth/LoginController.php
public function username()
{
return 'login';
}
看看 AuthenticatesUsers.php
中的其他函数。他们每个人都可以覆盖。但不要覆盖 vendors 文件夹中的文件。无论您更改什么,总有一天会在 composer update
.
之后被覆盖
在您的 loginController
中创建此函数
public function login(LoginRequest $request)
{
$user = User::select('id')->where('user_name', $request->user_name)->where('pin', $request->pin)->first();
if ($user) {
Auth::loginUsingId($user->id);
return redirect()->intended('/dashboard');
} else {
return redirect()->back()->with('app_warning', 'Credenciales Invalidas!')->withInput();
}
}
在 database
上为您的字段更改此 user->name and pin
欢迎来到 Stack Overflow。
如果您查看 Laravel 身份验证文档,有一个名为 "Authentication Quickstart" 的部分和一个名为 "Authentication -> Username Customization" 的小节。这显示了 LoginController
上的方法,您需要定义该方法以调整用作用户名的字段,默认情况下 email
。
public function username()
{
return 'login';
}
Laravel 5.6 Docs - Authentication - Authentication Quickstart
我对 Laravel 很陌生,在使用 auth 选项时遇到了一些问题。 我正在尝试在另一个自定义 table 上使用身份验证。我已经设置了与新 table 的连接,但是 Laravel 仍在搜索电子邮件字段。在我的 table 中有 'login' 字段。我不知道在哪里更改它,有人可以帮忙吗?
我正在使用 Laravel 5.6
我创建了新模型并将受保护的 $table
添加到 User(默认)模型。
那是我的错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause'
您可以覆盖文件 vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
中的任何函数。在您的情况下,您只需将其添加到 app/Http/Controllers/Auth/LoginController.php
public function username()
{
return 'login';
}
看看 AuthenticatesUsers.php
中的其他函数。他们每个人都可以覆盖。但不要覆盖 vendors 文件夹中的文件。无论您更改什么,总有一天会在 composer update
.
在您的 loginController
public function login(LoginRequest $request)
{
$user = User::select('id')->where('user_name', $request->user_name)->where('pin', $request->pin)->first();
if ($user) {
Auth::loginUsingId($user->id);
return redirect()->intended('/dashboard');
} else {
return redirect()->back()->with('app_warning', 'Credenciales Invalidas!')->withInput();
}
}
在 database
user->name and pin
欢迎来到 Stack Overflow。
如果您查看 Laravel 身份验证文档,有一个名为 "Authentication Quickstart" 的部分和一个名为 "Authentication -> Username Customization" 的小节。这显示了 LoginController
上的方法,您需要定义该方法以调整用作用户名的字段,默认情况下 email
。
public function username()
{
return 'login';
}
Laravel 5.6 Docs - Authentication - Authentication Quickstart