【问题标题】:Override password reset url in email template Laravel 5.3在电子邮件模板 Laravel 5.3 中覆盖密码重置 url
【发布时间】:2017-12-19 16:03:43
【问题描述】:

我正在尝试覆盖放入电子邮件中的 actionUrl 以重置用户帐户。但无论我做什么,它都保持不变。我尝试在我的 Route 文件中覆盖。有人可以帮帮我吗?

这是我的路线文件中的路线:

Route::get('cms/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');

这是我的电子邮件模板:

<p style="{{ $style['paragraph-sub'] }}">
    <a style="{{ $style['anchor'] }}" href="{{ $actionUrl }}" target="_blank">
        {{ $actionUrl }}
    </a>
</p>` 

我知道 actionUrl 是在 SimpleMessage.php 中定义的,但我不知道它在哪里设置。

【问题讨论】:

    标签: laravel email routing passwords reset


    【解决方案1】:

    链接设置在Illuminate\Auth\Notifications\ResetPassword。这是密码重置请求发出的通知。

    此通知在 Illuminate\Auth\Passwords\CanResetPassword 中初始化,这是一个在其他任何地方都没有的特征,而不是您的 App\User 模型。

    所以您需要做的就是创建自己的重置通知并覆盖您的User 模型上的sendPasswordResetNotification 方法,如下所示:


    php artisan make:notification MyResetPasswordNotification

    编辑app/Notifications/MyResetPasswordNotification.php

    <?php
    
    namespace App\Notifications;
    
    use Illuminate\Notifications\Messages\MailMessage;
    
    
    class MyResetPasswordNotification extends \Illuminate\Auth\Notifications\ResetPassword
    {
        /**
         * Build the mail representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return \Illuminate\Notifications\Messages\MailMessage
         */
        public function toMail($notifiable)
        {
            return (new MailMessage)
                ->line('You are receiving this email because we received a password reset request for your account.')
                ->action('Reset Password', url('YOUR URL', $this->token))
                ->line('If you did not request a password reset, no further action is required.');
        }
    }
    

    然后将此添加到app/User.php

    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new \App\Notifications\MyResetPasswordNotification($token));
    }
    

    当然,您需要创建自己的路线,正如您在问题中所写的那样,您还必须更改刀片视图。

    【讨论】:

    猜你喜欢
    • 2015-10-18
    • 2017-02-26
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多