#會員註冊Auth套件與相關概念

1.使用laravel官方Passprot套件先安裝

composer require laravel/passport

2.根據文件要求需要安裝migrate,系統會幫我們創建需要的table

php artisan migrate

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/19f1e966-6075-462e-8300-a6c8781a1d1e/1628143615089.jpg

3.安裝產生相關的加密密鑰。該命令將創建“個人訪問”和“密碼授予”客戶端,用於生成訪問TOKENS

php artisan passport:install

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f5f1381c-04a6-423a-966e-8b4283d153ee/1628143822128.jpg

4.根據官網引用use Laravel\Passport\HasApiTokens;到我們的App\Models\User模型中

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/30ebec47-ee17-44bd-9393-0454597e73f9/1628144118895.jpg

5.接著設定AuthServiceProvider

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7b0e538f-9b85-47ba-961f-e7c13c219814/1628144723867.jpg

6.在應用程序config/auth.php配置文件中,將身份驗證防護的driver選項設置api為passport.

1629041380496.jpg

6.接著我們要設定一個controller來設定我們註冊的邏輯

php artisan make:controller AuthController

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fca8a728-cbe6-4479-8a07-f1a00cd4322a/1628146013680.jpg