Ray Lee | 李宗叡
Learn or Die
Published in
5 min readDec 31, 2020

--

Photo by Jason Dent on Unsplash

# 版本

Laravel 7.x

# 前言

我喜歡使用 Laravel 開發的感覺, 除了開發快速, 程式碼簡潔且優雅之外, Laravel 框架本身也是一個很好的學習參照物。 本篇主要將官方文件重點整理成 Q&A 的形式呈現, 原子化的概念, 這方式並不適用於每個人, 但若對你有幫助, 我會很開心。

# 目錄

Laravel — 官方文件原子化翻譯 — 目錄

# Introduction

Laravel Password Reset 中, 若要使用預設的 password reset feature, User model 需要 use 哪一個 trait?

  1. Illuminate\Notifications\Notifiable trait
  2. Illuminate\Auth\Passwords\CanResetPassword trait

# Database Considerations

Laravel Password Reset 中, 若要使用預設 password reset feature, 務必 implement 哪一個 interface?

Illuminate\Contracts\Auth\CanResetPassword interface

# Generating The Reset Token Table Migration

Laravel Password Reset 中, password reset 會儲存 password reset token 在資料庫, 這個預設的 migration 可使用哪個 CLI 建立?

composer require laravel/ui

php artisan migrate

# Routing

Laravel Password Reset 中, 預設已寫好發送 email password reset link 以及 reset user password 的 Auth\ForgotPasswordController 以及 Auth\ResetPasswordController, 若要使用 CLI 通往這兩個 Controller 的 route, 該怎麼做?

composer requrie laravel/ui

php artisan ui vue --auth

# Views

Laravel Password Reset 中, 若要使用 CLI 來產生 password reset 的 view, 該怎麼做?

composer require laravel/ui
php artisan ui vue --auth

# After Resetting Passwords

Laravel Password Reset 中, 在 password reset 之後, 會自動重導到 /home, 若要將 /home 改成 /dashboard, 可以在哪個檔案中的 $redirectTo property 修改?

ResetPasswordController

以下位於 ResetPasswordController 的 Laravel example code 的意思是?

  • Example:
<?php
protected $redirectTo = '/dashboard';
  • Answer: Laravel 預設當 password reset 後, 會自動 redirect 到 /home, 若要 redirect 到其他地方, 可在 ResetPasswordController 中的 $redirectTo property 定義

Laravel Password Reset 中, 預設 password reset tokens 會在幾個小時後失效?

1 小時

Laravel Password Reset 中, 預設 password reset tokens 會在一個小時後失效, 若要自定義, 可在哪個檔案?

config/auth.php expire option

# Customization

以下的 Laravel example code 的意思是?

  • Example:
<?php
use Illuminate\Support\Facades\Password;

public function broker()
{
return Password::broker('name');
}
  • Answer: 如果你有一個以上的 user table 或 model, 有需求不使用預設設定的話, 可在 ForGotPasswordController 以及 ResetPasswordController 定義其他設定, 'name''config/auth.passwords' 中的定義

# Reset Email Customization

以下的 Laravel example code 的意思是?

  • Example:
<?php
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
  • Answer: Laravel 中, 當使用 scaffolding 時, 預設有 password reset 的功能, 如果想要變更通知的 notification class, 可在 Model 中使用 sendPasswordResetNotification method 自定義

Laravel Password Reset 中, 若我要自定義 reset password notification, 在以下的 example 中, 可以在哪個 class 中覆寫哪一個 sendPasswordResetNotification method?

User model

--

--

Ray Lee | 李宗叡
Learn or Die

It's Ray. I do both backend and frontend, but more focus on backend. I like coding, and would like to see the whole picture of a product.