12<?php34namespaceApp;56useIlluminate\Notifications\Notifiable;7useIlluminate\Foundation\Auth\Useras Authenticatable;89useApp\Notifications\CustomPasswordReset;// 追加1011classUserextendsAuthenticatable12{13useNotifiable;1415/**
16 * The attributes that are mass assignable.
17 *
18 * @vararray19 */20protected$fillable=[21'name','email','password',22];2324/**
25 * The attributes that should be hidden for arrays.
26 *
27 * @vararray28 */29protected$hidden=[30'password','remember_token',31];3233// ここから下を追加3435publicfunctionsendPasswordResetNotification($token)36{37$this->notify(newCustomPasswordReset($token));38}39}
3. リセットメールを再定義
修正前のものから内容を全て書き換えています。
app/Notifications/CustomPasswordReset.php
php
1<?php23namespaceApp\Notifications;45useIlluminate\Bus\Queueable;6useIlluminate\Notifications\Notification;7useIlluminate\Contracts\Queue\ShouldQueue;8useIlluminate\Notifications\Messages\MailMessage;910useIlluminate\Auth\Notifications\ResetPassword;// 追加1112classCustomPasswordResetextendsResetPassword// extendsをNotificationからResetPasswordに変更13{14/**
15 * The password reset token.
16 *
17 * @varstring18 */19public$token;2021/**
22 * Create a notification instance.
23 *
24 * @paramstring$token25 * @returnvoid26 */27publicfunction__construct($token)28{29$this->token=$token;30}3132/**
33 * Get the notification's channels.
34 *
35 * @parammixed$notifiable36 * @returnarray|string37 */38publicfunctionvia($notifiable)39{40return['mail'];41}4243/**
44 * Build the mail representation of the notification.
45 *
46 * @parammixed$notifiable47 * @return\Illuminate\Notifications\Messages\MailMessage48 */49publicfunctiontoMail($notifiable)50{51return(newMailMessage)52->subject('パスワードリセット')// メールの件名53->view('admin.emails.password')// resources/views/admin/emails/password.blade.phpを表示します54->action('Reset Password',url('admin/password/reset',$this->token));// $actionUrlという変数にトークン情報を含めたパスワードリセットのURLを格納します。これは上記のviewで参照可能です。55}56}
<?php
namespace App\Http\Controllers\Admin\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
protected $redirectTo = '/admin'; // 追加
/**
* Display the password reset view for the given token.
*
* If no token is present, display the link request form.
*
* @param \Illuminate\Http\Request $request
* @param string|null $token
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showResetForm(Request $request, $token = null)
{
return view('admin.passwords.reset')->with(
['token' => $token, 'email' => $request->email]
);
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。