在laravel中创建登录名,其中凭据不在同一数据库中 [英] Create a login in laravel where credentials are not in the same database
问题描述
我需要在laravel中创建一个到现有数据库的登录名.该数据库有点怪异的建模,但是我无法更改它.我对laravel还是很陌生,我无法弄清楚它是如何完成的.使用普通的make :: auth登录似乎很直观,但是我不知道如何更改参数,或者也许您为我提供了一个完全不同的解决方案.您将如何实现该登录?
I need to create a login to an existing database in laravel. The database is kinda weird modeled, yet I cannot change it. I'm quite new to laravel and I cannot figure out how it's done. The login with the normal make::auth seems intuitive, but I don't know how to change the parameters, or maybe you provide me with a completely different solution. How would you implement this login?
凭据分布在两个表中:
Table: Staff
-----
id
username
Table: Credential
-----
id
password (sha1)
id_staff
推荐答案
在您的config/auth.php中
In your config/auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database', // your database
// 'table' => 'users', // your table
// ],
],
您可以在此处进行更改并使用其他数据库和表.
Here you can make changes and use another database and table.
如果您的表位于同一数据库上,则只需要在此处使用表名
If your table is on the same database, you should only need table name here
'providers' => [
'credential' => [
'driver' => 'eloquent',
'model' => App\Credential::class,
],
],
在您的LoginController中
In your LoginController
public function userid()
{
$login = request()->input('login');
$field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'userid'; // you need to customize it to get email from the other table, if your email field is on other table
request()->merge([$field => $login]);
return $field;
}
这篇关于在laravel中创建登录名,其中凭据不在同一数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!