Laravel Auth のUserモデルを別モデルに書き換えたい
2532 ワード
ユーザー情報を保持し、それを閲覧する画面を作りたい時に困ったこと(Laravel5.5)
メモです。
<困ったこと>
UserモデルをAdminに書き換えたい(Userはログインしない)
Userモデルの時に作った認証機能を引き継ぎたい
<対処法>
1.
/config/auth.php
User ProvidersのモデルをApp\User::classからApp\Admin::classに書き換える
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
<困ったこと>
1.でログイン・ログアウトはできたけど、新規登録が出来ない
<対処法>
2.
/app/Http/Controllers/Auth/RegisterController.php
validatorファンクションの
emailのunique:usersをunique:adminsに書き換える
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:admins',
'password' => 'required|string|min:6|confirmed',
]);
}
ここはLaravel側でSQL叩いてるので、usersテーブルがないってエラーが出る
Author And Source
この問題について(Laravel Auth のUserモデルを別モデルに書き換えたい), 我々は、より多くの情報をここで見つけました https://qiita.com/tom01938572/items/104e0d34e3dcae615a3d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .