Đã đăng vào thg 2 14, 2019 2:55 SA 1 phút đọc 1 phút đọc
Hôm nay mình sẽ hướng dẫn viết API làm chức năng gửi e-mail khi Reset Password với Laravel Passport Authentication
Bước 1: Chỉnh sửa migration
Chỉnh sửa file migration database/migrations/xxx_create_password_resets_table.php
như bên dưới code:
public function up[]
{
Schema::create['password_resets', function [Blueprint $table] {
$table->increments['id'];
$table->string['email']->index[];
$table->string['token'];
$table->timestamps[];
}];
}
Bước 2: Tạo model Password Reset
Mở terminal chạy lệnh php artisan make:model Models/PasswordReset
Vào file app/Models/PasswordReset.php
được tạo ra ở command trên, thêm đoạn sau vào
code:
protected $fillable = [
'email',
'token',
];
Bước 3: Tạo Notifications
Chúng ta tạo ra file ResetPasswordRequest
để thông báo gửi mail đến người dùng
Mở terminal chạy lệnh php artisan make:notification ResetPasswordRequest
Command trên tạo file
protected $fillable = [
'email',
'token',
];
0, thêm đoạn code sau vàocode: