前提・実現したいこと
Illuminate/Foundation/Auth/AuthenticatesUsers.php
の
130行目
/** * Get the failed login response instance. * * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response * * @throws ValidationException */ protected function sendFailedLoginResponse(Request $request) { throw ValidationException::withMessages([ $this->username() => [trans('auth.failed')], ]); }
にて、ログインに失敗した際のメッセージをauth.failedから
出すように指定していますが、
ここで、userテーブルのstatus
(標準から追加した、
仮会員登録済であれば0、本会員であれば1、仮会員登録後メール認証済であれば2、退会済であれば9を
登録する項目です。)
ごとに出力するメッセージを変えたいです。
発生している問題・エラーメッセージ
Illuminate/Foundation/Auth/AuthenticatesUsers.php
は変更するわけにはいかないので、
LoginControllerにて下記の通り上書き処理を記載しています。
protected function sendFailedLoginResponse(Request $request) { $user = User::where('email', $request->email)->first(); if($user->status == 0 or 2){ throw ValidationException::withMessages([ $this->username() => [trans('auth.failed_provisional')], ]); }elseif($user->status == 9){ throw ValidationException::withMessages([ $this->username() => [trans('auth.failed_quit')], ]); }else{ throw ValidationException::withMessages([ $this->username() => [trans('auth.failed')], ]); } }
これで試した際、
Class 'ValidationException' not found
のエラーが発生してしまいます。
なので、
・まずエラーメッセージの制御の方法は上記の方法で正しいのかどうか
・エラーの解消方法はどうすればよいか
を伺いたいです。
尚、
エラーメッセージファイルは下記の通り記載しています。
「 {{url(/register/verify/.$token)}}',」
の部分にも不安があるのでおそらくエラーが発生するかと存じますが、
もしお分かりになればこちらの記載も正しいものかどうか見てくださると幸甚です。
<?php return [ /* |-------------------------------------------------------------------------- | Authentication Language Lines |-------------------------------------------------------------------------- | | The following language lines are used during authentication for various | messages that we need to display to the user. You are free to modify | these language lines according to your application's requirements. | */ 'failed' => '認証情報と一致するレコードがありません。', 'failed_provisional' => '該当のユーザーは仮登録の状態です。<br> 下記URLから本登録が可能です。<br> {{url(/register/verify/.$token)}}', 'failed_quit' => '既に退会したユーザーです', 'throttle' => 'ログインの試行回数が多すぎます。:seconds 秒後にお試しください。', ];
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/22 09:51