【问题标题】:Change the view in the reset password email using Laravel 5.3使用 Laravel 5.3 更改重置密码电子邮件中的视图
【发布时间】:2017-02-10 19:29:25
【问题描述】:

我正在使用 Laravel 5.3,我现在正在处理我的 CRM 上的重置密码选项。

我的 CRM 是多语言的,因此我需要根据客户的语言更改发送给客户的电子邮件模板/视图,实际上,我只需从 RTL 更改为 LTR - 此值设置在 cookie 上称为“user_direction”。

我正在使用包含 ResetPassword 类的 Laravel 默认引导验证。

这就是现在所拥有的:

<?php

namespace Illuminate\Auth\Notifications;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPassword extends Notification
{
    public $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        $url        = url('password/reset',$this->token);
        $subject    = trans('global.reset_password_email_subject'); 
        $greeting   = trans('global.reset_password_email_greeting'); 
        $line_01    = trans('global.reset_password_email_line_01'); 
        $action     = trans('global.reset_password_email_action'); 
        $line_02    = trans('global.reset_password_email_line_02'); 

        return (new MailMessage)
            ->subject($subject)
            ->greeting($greeting)
            ->line($line_01)
            ->action($action, $url)
            ->line($line_02);
    }
}

这是我想要的想法,但我不知道如何正确写:

    public function toMail($notifiable)
    {
        $url        = url('password/reset',$this->token);
        $subject    = trans('global.reset_password_email_subject'); 
        $greeting   = trans('global.reset_password_email_greeting'); 
        $line_01    = trans('global.reset_password_email_line_01'); 
        $action     = trans('global.reset_password_email_action'); 
        $line_02    = trans('global.reset_password_email_line_02'); 

        $view = "notifications::email";
        if($request->cookie('user_direction') == "rtl"):
            $view = "notifications::email-rtl";
        endif;

        return (new MailMessage)
            ->view($view)
            ->subject($subject)
            ->greeting($greeting)
            ->line($line_01)
            ->action($action, $url)
            ->line($line_02);
    }

感谢您的帮助!

【问题讨论】:

    标签: php laravel laravel-5.3 laravel-mail


    【解决方案1】:

    在 youtube 上看了一些对我有用的教程后,我是这样写的:

    首先我添加“使用Cookie;”

    public function toMail($notifiable)
    {
        $user_language_direction = Cookie::get('user_direction');
    
        $url        = url('password/reset',$this->token);
        $subject    = trans('global.reset_password_email_subject'); 
        $greeting   = trans('global.reset_password_email_greeting'); 
        $line_01    = trans('global.reset_password_email_line_01'); 
        $action     = trans('global.reset_password_email_action'); 
        $line_02    = trans('global.reset_password_email_line_02'); 
    
        $view       = "notifications::email";
        if($user_language_direction == "rtl")
            $view   = "notifications::email-rtl";
    
        return (new MailMessage)
            ->view($view,array())
            ->subject($subject)
            ->greeting($greeting)
            ->line($line_01)
            ->action($action, $url)
            ->line($line_02);
    }
    

    【讨论】:

      【解决方案2】:

      您可以通过覆盖中的函数来更改重置密码视图

      use Illuminate\Foundation\Auth\ResetsPasswords 特质。

      只需在类中添加如下函数

      App\Http\Controllers\Auth\ResetPasswordController

      修改你的观点。

      /**
       * 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('auth.passwords.reset')->with(
              ['token' => $token, 'email' => $request->email]
          );
      }
      

      【讨论】:

      • 嗨 Saravanan Sampathkumar,这不是我的意思,我想更改发送给用户以重置密码的邮件,邮件的内容是一个视图,如果我想更改此视图用户使用 RTL 或 LTR
      猜你喜欢
      • 2016-07-14
      • 1970-01-01
      • 2017-12-19
      • 2019-12-21
      • 2017-03-27
      • 1970-01-01
      • 2019-12-06
      • 2012-05-16
      • 1970-01-01
      相关资源
      最近更新 更多