adminでログインしようとするとThese credentials do not match our recordsが出てログイン出来ません。
下記のサイトを参考にしながらユーザーのマルチ認証をしています。
https://qiita.com/namizatop/items/5d56d96d4c255a0e3a87?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items#auth
userの方はログインも新規登録もうまくいくのですが、
adminは新規登録するとログイン画面に飛ばされます(データベースには登録されている)。
ログインしようとするとThese credentials do not match our recordsが出てきます。
検索したサイト
https://reffect.co.jp/laravel/laravel-authentification-by-code-base
https://stackoverflow.com/questions/48268978/laravel-auth-these-credentials-do-not-match-our-records
register
1<?php 2 3namespace App\Http\Controllers\Admin\Auth; 4 5use App\Http\Controllers\Controller; 6use App\Providers\RouteServiceProvider; 7use App\Models\Admin; 8use Illuminate\Foundation\Auth\RegistersUsers; 9use Illuminate\Support\Facades\Hash; 10use Illuminate\Support\Facades\Validator; 11use Illuminate\Http\Request; 12use Illuminate\Auth\Events\Registered; 13use Illuminate\Support\Facades\Auth; 14 15class RegisterController extends Controller 16{ 17 /* 18 |-------------------------------------------------------------------------- 19 | Register Controller 20 |-------------------------------------------------------------------------- 21 | 22 | This controller handles the registration of new users as well as their 23 | validation and creation. By default this controller uses a trait to 24 | provide this functionality without requiring any additional code. 25 | 26 */ 27 28 use RegistersUsers; 29 30 /** 31 * Where to redirect users after registration. 32 * 33 * @var string 34 */ 35 protected $redirectTo = RouteServiceProvider::ADMIN_HOME; 36 37 /** 38 * Create a new controller instance. 39 * 40 * @return void 41 */ 42 public function __construct() 43 { 44 $this->middleware('guest:admin'); 45 } 46 47 // Guardの認証方法を指定 48 protected function guard() 49 { 50 return Auth::guard('admin'); 51 } 52 53 // 新規登録画面 54 public function showRegistrationForm() 55 { 56 return view('admin.auth.register'); 57 } 58 59 /** 60 * Get a validator for an incoming registration request. 61 * 62 * @param array $data 63 * @return \Illuminate\Contracts\Validation\Validator 64 */ 65 // バリデーション 66 protected function validator(array $data) 67 { 68 return Validator::make($data, [ 69 'name' => ['required', 'string', 'max:255'], 70 'email' => ['required', 'string', 'email', 'max:255', 'unique:admins'], 71 'password' => ['required', 'string', 'min:8', 'confirmed'], 72 ]); 73 } 74 75 /** 76 * Create a new user instance after a valid registration. 77 * 78 * @param array $data 79 * @return \App\Models\Admin 80 */ 81 // 登録処理 82 protected function create(array $data) 83 { 84 return Admin::create([ 85 'name' => $data['name'], 86 'email' => $data['email'], 87 'password' => Hash::make($data['password']), 88 ]); 89 } 90} 91
login
1<?php 2 3namespace App\Http\Controllers\Admin\Auth; 4 5use App\Http\Controllers\Controller; 6use App\Providers\RouteServiceProvider; 7use Illuminate\Foundation\Auth\AuthenticatesUsers; 8use Illuminate\Http\Request; 9use Illuminate\Support\Facades\Auth; 10 11class LoginController extends Controller 12{ 13 /* 14 |-------------------------------------------------------------------------- 15 | Login Controller 16 |-------------------------------------------------------------------------- 17 | 18 | This controller handles authenticating users for the application and 19 | redirecting them to your home screen. The controller uses a trait 20 | to conveniently provide its functionality to your applications. 21 | 22 */ 23 24 use AuthenticatesUsers; 25 26 /** 27 * Where to redirect users after login. 28 * 29 * @var string 30 */ 31 protected $redirectTo = RouteServiceProvider::ADMIN_HOME; 32 33 /** 34 * Create a new controller instance. 35 * 36 * @return void 37 */ 38 public function __construct() 39 { 40 $this->middleware('guest:admin')->except('logout'); 41 } 42 43 // Guardの認証方法を指定 44 protected function guard() 45 { 46 return Auth::guard('admin'); 47 } 48 49 // ログイン画面 50 public function showLoginForm() 51 { 52 return view('admin.auth.login'); 53 } 54 55 // ログアウト処理 56 public function logout(Request $request) 57 { 58 Auth::guard('admin')->logout(); 59 60 return $this->loggedOut($request); 61 } 62 63 // ログアウトした時のリダイレクト先 64 public function loggedOut() 65 { 66 return redirect(route('admin.login')); 67 } 68} 69
auth
1<?php 2 3return [ 4 5 /* 6 |-------------------------------------------------------------------------- 7 | Authentication Defaults 8 |-------------------------------------------------------------------------- 9 | 10 | This option controls the default authentication "guard" and password 11 | reset options for your application. You may change these defaults 12 | as required, but they're a perfect start for most applications. 13 | 14 */ 15 16 'defaults' => [ 17 'guard' => 'user', 18 'passwords' => 'users', 19 ], 20 21 /* 22 |-------------------------------------------------------------------------- 23 | Authentication Guards 24 |-------------------------------------------------------------------------- 25 | 26 | Next, you may define every authentication guard for your application. 27 | Of course, a great default configuration has been defined for you 28 | here which uses session storage and the Eloquent user provider. 29 | 30 | All authentication drivers have a user provider. This defines how the 31 | users are actually retrieved out of your database or other storage 32 | mechanisms used by this application to persist your user's data. 33 | 34 | Supported: "session", "token" 35 | 36 */ 37 38 'guards' => [ 39 'user' => [ 40 'driver' => 'session', 41 'provider' => 'users', 42 ], 43 44 // Admin用の認証を追加 45 'admin' => [ 46 'driver' => 'session', 47 'provider' => 'admins', 48 ], 49 50 'api' => [ 51 'driver' => 'token', 52 'provider' => 'users', 53 'hash' => false, 54 ], 55 ], 56 57 /* 58 |-------------------------------------------------------------------------- 59 | User Providers 60 |-------------------------------------------------------------------------- 61 | 62 | All authentication drivers have a user provider. This defines how the 63 | users are actually retrieved out of your database or other storage 64 | mechanisms used by this application to persist your user's data. 65 | 66 | If you have multiple user tables or models you may configure multiple 67 | sources which represent each model / table. These sources may then 68 | be assigned to any extra authentication guards you have defined. 69 | 70 | Supported: "database", "eloquent" 71 | 72 */ 73 74 'providers' => [ 75 'users' => [ 76 'driver' => 'eloquent', 77 'model' => App\Models\User::class, 78 ], 79 80 'admins' => [ 81 'driver' => 'eloquent', 82 'model' => App\Models\Admin::class, 83 ], 84 85 // 'users' => [ 86 // 'driver' => 'database', 87 // 'table' => 'users', 88 // ], 89 ], 90 91 /* 92 |-------------------------------------------------------------------------- 93 | Resetting Passwords 94 |-------------------------------------------------------------------------- 95 | 96 | You may specify multiple password reset configurations if you have more 97 | than one user table or model in the application and you want to have 98 | separate password reset settings based on the specific user types. 99 | 100 | The expire time is the number of minutes that the reset token should be 101 | considered valid. This security feature keeps tokens short-lived so 102 | they have less time to be guessed. You may change this as needed. 103 | 104 */ 105 106 'passwords' => [ 107 'users' => [ 108 'provider' => 'users', 109 'table' => 'password_resets', 110 'expire' => 60, 111 'throttle' => 60, 112 ], 113 114 'admins' => [ 115 'provider' => 'admins', 116 'table' => 'password_resets', 117 'expire' => 60, 118 'throttle' => 60, 119 ], 120 ], 121 122 /* 123 |-------------------------------------------------------------------------- 124 | Password Confirmation Timeout 125 |-------------------------------------------------------------------------- 126 | 127 | Here you may define the amount of seconds before a password confirmation 128 | times out and the user is prompted to re-enter their password via the 129 | confirmation screen. By default, the timeout lasts for three hours. 130 | 131 */ 132 133 'password_timeout' => 10800, 134 135]; 136
試したこと
・パスワードの作り方をHash::make('password')とbcryptを使ってやってみるも変化なしでした。
・キャッシュ削除。https://qiita.com/ucan-lab/items/c1e561d20cc591966c25
・ユーザーの作り直し
自分の力では原因を掴めずにいます。
知恵を貸していただきたいです。
よろしくおねがします。
php7.4.2
laravel 6.0

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。