laravel - 为默认身份验证路由添加前缀
问题描述
我已将前缀用户添加到默认身份验证路由,以便我可以实现 example.com/user/login 路由。除了发送到用户电子邮件地址的密码重置电子邮件外,一切正常。单击电子邮件中的链接时,它会转到默认的重置路线。如何将前缀用户添加到电子邮件中的此链接。
任何帮助表示赞赏。
如果有帮助,这是代码
Route::group(['prefix' => 'user'], function () {
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
});
解决方案
您需要为密码重置创建通知类
php artisan make:notification MailResetPasswordToken
之后编辑您在新文件夹中找到的此文件App\Notifications
并更改url('password/reset', $this->token)
为url('user/password/reset', $this->token)
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class MailResetPasswordToken extends Notification
{
use Queueable;
public $token;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject("Reset your password")
->line("Hey, did you forget your password? Click the button to reset it.")
->action('Reset Password', url('user/password/reset', $this->token))
->line('Thankyou for being a friend');
}
}
User.php
使用用户模型中的本地实现覆盖发送密码重置特征。确保您的User
模型应该使用Notifiable
特征
/**
* Send a password reset email to the user
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new MailResetPasswordToken($token));
}
将这些类导入User
模型
use App\Notifications\MailResetPasswordToken;
use Illuminate\Notifications\Notifiable;
推荐阅读
- android - 如何应用随机数字列表从数组中选择以选择图像?
- python - LinkedList 删除功能正在删除 2 个节点
- c# - 在Unity / c#中向firebase发出请求后返回字符串
- c - C 中的 Windows DLL 注入器不注入 DLL
- pandas - 如何使用 pandas 操作数组中的数据
- arrays - 从字符串的开头查找单词的特定数量
- javascript - 如何找到特定数字的所有可能排列?
- javascript - 在 Javascript 中替换/附加 HREF 文件类型扩展名
- holoviews - 如何在 holoviews 布局中对齐网格空间图?
- typescript - Typescript如何处理本机接口