如何解决如何在电子邮件中为 laravel 上的 api 路由和 web 路由创建不同的密码重置链接
所以我正在尝试为路由 API 制作一个忘记密码的功能 当用户访问该功能时,他将收到一封电子邮件,其中包含重置密码的链接。并且邮件中的链接会根据用户使用的路线而有所不同。
示例: 当用户访问API路由时,用户收到的链接是http://website.com/api/password/reset,用户访问web路由时,收到的链接是http://webiste.com/password/reset
我尝试使用 Request :: is ('api *')
并且它在本地服务器上运行流畅,但是当我部署到 heroku 时,Request :: is ('api *')
命令不起作用,因此发送的链接指向我使用的网络路由Request :: is ('api *')
内 ResetPasswordNotification
<?php
namespace Illuminate\Auth\Notifications;
use Illuminate\Http\Request;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Lang;
// use Illuminate\Support\Facades\Request;
class ResetPassword extends Notification
{
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* The callback that should be used to create the reset password URL.
*
* @var \Closure|null
*/
public static $createUrlCallback;
/**
* The callback that should be used to build the mail message.
*
* @var \Closure|null
*/
public static $toMailCallback;
/**
* Create a notification instance.
*
* @param string $token
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback,$notifiable,$this->token);
}
if (static::$createUrlCallback) {
$url = call_user_func(static::$createUrlCallback,$this->token);
} else {
$request = new Request;
if($request->is('api*')){
$url = url(route('api.password.reset',[
'token' => $this->token,'email' => $notifiable->getEmailForPasswordReset(),],false));
}else{
$url = url(route('password.reset',false));
}
}
return (new MailMessage)
->subject(Lang::get('Reset Password Notification'))
->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
->action(Lang::get('Reset Password'),$url)
->line(Lang::get('This password reset link will expire in :count minutes.',['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
->line(Lang::get('If you did not request a password reset,no further action is required.'));
}
/**
* Set a callback that should be used when creating the reset password button URL.
*
* @param \Closure $callback
* @return void
*/
public static function createUrlUsing($callback)
{
static::$createUrlCallback = $callback;
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}
上面的命令在本地服务器上运行流畅,没有任何错误,但在heroku上不起作用。
我请求你帮助解决这个问题。 谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。