質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

解決済

1回答

2105閲覧

laravel パスワードリセットのメール機能をマルチ認証でも使いたい。

neginattofan

総合スコア66

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

0グッド

0クリップ

投稿2020/05/11 05:59

編集2020/05/11 06:35

前提・実現したいこと

laravel 5.8
一般ユーザー(user)のパスワードリセットのためのメール機能は問題なく動いています。
もう一つのユーザー(company)をマルチ認証できるように作りました。

発生している問題・エラーメッセージ

companyユーザーにuserとは別のviewを与えることはできましたが(下記のshowLinkRequestForm()でcompany側のviewを返している )、controllerのemailチェックがおそらく別れていいません。

なので、company側のviewでcompany側の登録してあるemailでメールを送信しようとしても『ユーザーは存在しません』とエラーになり、

company側のviewでuser側で登録してあるemailでメールを送信するとうまく送信できるようになっています。

このような場合はコントローラーのどこに不具合があるのでしょうか?

よろしくお願いします。

*company側のemail機能をまとめたcontrollerです。

ForgetPasswordController

1<?php 2 3namespace App\Http\Controllers\AuthCompany; 4 5use App\Http\Controllers\Controller; 6use Illuminate\Foundation\Auth\SendsPasswordResetEmails; 7 8use Illuminate\Http\Request; 9use Illuminate\Support\Facades\Password; 10 11class ForgotPasswordController extends Controller 12{ 13 /* 14 |-------------------------------------------------------------------------- 15 | Password Reset Controller 16 |-------------------------------------------------------------------------- 17 | 18 | This controller is responsible for handling password reset emails and 19 | includes a trait which assists in sending these notifications from 20 | your application to your users. Feel free to explore this trait. 21 | 22 */ 23 24 /** 25 * Create a new controller instance. 26 * 27 * @return void 28 */ 29 public function __construct() 30 { 31 $this->middleware('guest:company'); 32 } 33 34 public function showLinkRequestForm() { 35 return view('company_auth.passwords.email'); 36 } 37 38 /** 39 * Send a reset link to the given user. 40 * 41 * @param \Illuminate\Http\Request $request 42 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse 43 */ 44 public function sendResetLinkEmail(Request $request) 45 { 46 $this->validateEmail($request); 47 48 // We will send the password reset link to this user. Once we have attempted 49 // to send the link, we will examine the response then see the message we 50 // need to show to the user. Finally, we'll send out a proper response. 51 $response = $this->broker()->sendResetLink( 52 $this->credentials($request) 53 ); 54 55 return $response == Password::RESET_LINK_SENT 56 ? $this->sendResetLinkResponse($request, $response) 57 : $this->sendResetLinkFailedResponse($request, $response); 58 } 59 60 /** 61 * Validate the email for the given request. 62 * 63 * @param \Illuminate\Http\Request $request 64 * @return void 65 */ 66 protected function validateEmail(Request $request) 67 { 68 $request->validate(['email' => 'required|email']); 69 } 70 71 /** 72 * Get the needed authentication credentials from the request. 73 * 74 * @param \Illuminate\Http\Request $request 75 * @return array 76 */ 77 protected function credentials(Request $request) 78 { 79 return $request->only('email'); 80 } 81 82 /** 83 * Get the response for a successful password reset link. 84 * 85 * @param \Illuminate\Http\Request $request 86 * @param string $response 87 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse 88 */ 89 protected function sendResetLinkResponse(Request $request, $response) 90 { 91 return back()->with('status', trans($response)); 92 } 93 94 /** 95 * Get the response for a failed password reset link. 96 * 97 * @param \Illuminate\Http\Request $request 98 * @param string $response 99 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse 100 */ 101 protected function sendResetLinkFailedResponse(Request $request, $response) 102 { 103 return back() 104 ->withInput($request->only('email')) 105 ->withErrors(['email' => trans($response)]); 106 } 107 108 /** 109 * Get the broker to be used during password reset. 110 * 111 * @return \Illuminate\Contracts\Auth\PasswordBroker 112 */ 113 public function broker() 114 { 115 return Password::broker(); 116 } 117} 118

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

オーバーライドしたらできました

投稿2020/05/29 03:02

neginattofan

総合スコア66

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問