如何在 Laravel5.3 中更改密码重置 link?
How to change password reset link in Laravel5.3?
我用 php artisan make:auth 重设了密码。
我知道在调用 $actionUrl
的变量中重置密码 link
这样生成link。
http://example.com/program/password/reset/73d9b7b71a1782476dcd12fa438b839fc0a8aed1b7bfe1fad7d5c6909e45c11b
我想做的就是这样改变link
http://example.com/program/admin/password/reset/73d9b7b71a1782476dcd12fa438b839fc0a8aed1b7bfe1fad7d5c6909e45c11b
我认为link是由href+token组成的。
所以我尝试自定义 link,但这是错误的。
app/User.php -- 将邮件正文从供应商视图更改为自己视图
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\CustomPasswordReset;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new CustomPasswordReset($token));
}
}
app/Notificantions/CustomPasswordReset.php -- 显示自己对邮件正文的看法
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class CustomPasswordReset extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* 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)->view('admin.emails.password');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
resources/views/admin/emails/password.blade.php
<a href="{{ url('/admin/password/reset', csrf_token()) }}">{{ url('/admin/password/reset', csrf_token()) }}</a>
我应该在哪里更改?
我自己解决了这个问题。
在这里您可以更改变量 $actionUrl。
app/User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\CustomPasswordReset;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new CustomPasswordReset($token));
}
}
app/Notificantions/CustomPasswordReset.php
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Auth\Notifications\ResetPassword; // add this.
class CustomPasswordReset extends ResetPassword // change extends from Notification to ResetPassword
{
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* 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)
{
return (new MailMessage)
->view('admin.emails.password')
->action('Reset Password', url('admin/password/reset', $this->token)); // add this. this is $actionUrl
}
}
resources/views/admin/emails/password.blade.php
Password Reset Mail View bla bla bla... No need Doctype or html or body tag.
$actionUrl display like this http://example.com/admin/password/reset/61afe571218324aab602e4a0d9054d2bb2039e886addef7f072c01fc9f155264
<br />
<a href="{{ $actionUrl }}">{{ $actionUrl }}</a>
我用 php artisan make:auth 重设了密码。
我知道在调用 $actionUrl
的变量中重置密码 link这样生成link。
http://example.com/program/password/reset/73d9b7b71a1782476dcd12fa438b839fc0a8aed1b7bfe1fad7d5c6909e45c11b
我想做的就是这样改变link
http://example.com/program/admin/password/reset/73d9b7b71a1782476dcd12fa438b839fc0a8aed1b7bfe1fad7d5c6909e45c11b
我认为link是由href+token组成的。 所以我尝试自定义 link,但这是错误的。
app/User.php -- 将邮件正文从供应商视图更改为自己视图
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\CustomPasswordReset;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new CustomPasswordReset($token));
}
}
app/Notificantions/CustomPasswordReset.php -- 显示自己对邮件正文的看法
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class CustomPasswordReset extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* 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)->view('admin.emails.password');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
resources/views/admin/emails/password.blade.php
<a href="{{ url('/admin/password/reset', csrf_token()) }}">{{ url('/admin/password/reset', csrf_token()) }}</a>
我应该在哪里更改?
我自己解决了这个问题。
在这里您可以更改变量 $actionUrl。
app/User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\CustomPasswordReset;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new CustomPasswordReset($token));
}
}
app/Notificantions/CustomPasswordReset.php
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Auth\Notifications\ResetPassword; // add this.
class CustomPasswordReset extends ResetPassword // change extends from Notification to ResetPassword
{
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* 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)
{
return (new MailMessage)
->view('admin.emails.password')
->action('Reset Password', url('admin/password/reset', $this->token)); // add this. this is $actionUrl
}
}
resources/views/admin/emails/password.blade.php
Password Reset Mail View bla bla bla... No need Doctype or html or body tag.
$actionUrl display like this http://example.com/admin/password/reset/61afe571218324aab602e4a0d9054d2bb2039e886addef7f072c01fc9f155264
<br />
<a href="{{ $actionUrl }}">{{ $actionUrl }}</a>