我正在使用 Laravel 5.3,我现在正在处理我的 CRM 上的重置密码选项。
我的 CRM 是多语言的,因此我需要根据客户的语言更改电子邮件模板/发送给客户的视图,实际上,我只需从 RTL 更改为 LTR - 此值设置在名为“user_direction”的 cookie 上”。
我正在使用包含 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);
}
谢谢您的帮助!