Bạn có thể thay đổi chủ đề email đặt lại mật khẩu của mình nhưng sẽ cần thêm một số công việc. Trước tiên, bạn cần tạo triển khai của riêng mình cho thông báo ResetPassword
.
Tạo một lớp thông báo mới bên app\Notifications
thư mục, chúng ta hãy đặt tên nó ResetPassword.php
:
<?php
namespace App\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)
{
return (new MailMessage)
->subject('Your Reset Password Subject Here')
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
}
Bạn cũng có thể tạo ra các mẫu thông báo sử dụng lệnh thợ thủ công:
php artisan make:notification ResetPassword
Hoặc bạn chỉ có thể copy-paste mã trên. Như bạn có thể thấy lớp thông báo này khá giống với lớp mặc định Illuminate\Auth\Notifications\ResetPassword
. Bạn thực sự có thể mở rộng nó từ lớp mặc định ResetPassword
.
Sự khác biệt duy nhất là ở đây, bạn thêm một lời gọi phương thức mới để xác định chủ đề của email:
return (new MailMessage)
->subject('Your Reset Password Subject Here')
Bạn có thể đọc thêm về Mail Notifications here.
Thứ hai, trên tệp app\User.php
, bạn cần ghi đè phương thức mặc định sendPasswordResetNotification()
được xác định bởi Illuminate\Auth\Passwords\CanResetPassword
đặc điểm. Bây giờ bạn nên sử dụng triển khai ResetPassword
của riêng mình:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\ResetPassword as ResetPasswordNotification;
class User extends Authenticatable
{
use Notifiable;
...
public function sendPasswordResetNotification($token)
{
// Your your own implementation.
$this->notify(new ResetPasswordNotification($token));
}
}
Và bây giờ, chủ đề email đặt lại mật khẩu của bạn sẽ được cập nhật!
Hy vọng trợ giúp này!
và làm thế nào chúng ta có thể thay đổi liên quan đến Laravel và Laravel được viết ở trên cùng. – Steve
@Steve Chuyển đến config/app.php và thay đổi tên ứng dụng – kniteli