Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel 8中创建自定义身份验证?_Php_Laravel - Fatal编程技术网

Php 如何在laravel 8中创建自定义身份验证?

Php 如何在laravel 8中创建自定义身份验证?,php,laravel,Php,Laravel,如何在laravel 8中使用预先存在的表(但表名为Users\u system not Users)创建自定义身份验证,并且该表(Users\u system)充满数据,并且没有与laravel用户相同的字段?数据库中不必有相同的字段。如果要为新表创建新模型,请创建UserSystem模型,并将所有App\User实例替换为App\UserSystem模型 如果要使用现有模型,只需在App\User模型中更改表名即可 如果您有不同的用户名或任何身份验证凭据,则需要将illumb\Foundat

如何在laravel 8中使用预先存在的表(但表名为Users\u system not Users)创建自定义身份验证,并且该表(Users\u system)充满数据,并且没有与laravel用户相同的字段?

数据库中不必有相同的字段。如果要为新表创建新模型,请创建UserSystem模型,并将所有
App\User
实例替换为
App\UserSystem
模型

如果要使用现有模型,只需在
App\User
模型中更改表名即可

如果您有不同的用户名或任何身份验证凭据,则需要将
illumb\Foundation\Auth\AuthenticatesUsers
类代码移动到
App\Http\Controllers\Auth\LoginController

以下是您需要在此处更改的代码段

protected function validateLogin(Request $request)
{
    $request->validate([
        $this->username() => 'required|string',
        'password' => 'required|string',
    ]);
}

protected function credentials(Request $request)
{
    return $request->only($this->username(), 'password');
}

//Mention your username here
public function username()
{
    return 'user_name';
}

欢迎来到苏。您可以基于
会话
cookies
创建自己的身份验证系统,并创建自己的中间件来保护