LoginSignup
4
6

More than 3 years have passed since last update.

Laravel 7.x で Auth を利用する

Last updated at Posted at 2020-07-06

Laravel 7系で Auth を使おうとしたら、5系のコマンドが通らなかったので個人の備忘として。

結論

5系まで使用していた以下のコマンドは、6系以降は変更になってます。

$ php artisan make:auth

  Command "make:auth" is not defined.
  // 【以下省略】

代わりに以下を使って下さい。
https://readouble.com/laravel/7.x/ja/authentication.html

New.
$ composer require laravel/ui
$ php artisan ui vue --auth

実際の流れ

インストール

  • laravel/ui の composerインストール
$ composer require laravel/ui
Using version ^2.0 for laravel/ui
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
30 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
  • Auth の認証スカフォールドを生成
$ php artisan ui vue --auth
Vue scaffolding installed successfully.
Please run "npm install && npm run dev" to compile your fresh scaffolding.
Authentication scaffolding generated successfully.
  • Vueまわりのパッケージをインストールする
    ログイン画面やユーザ登録画面のCSS準備などにも必要で、この時点でログインページを表示すると崩れます
$ npm install && npm run dev

DBをマイグレーション

ここまでの手順で、以下の通り必要なマイグレーションファイルは自動で生成されます。

$ ls -l database/migrations/
total 12
-rw-rw-r-- 1 appdev appdev 798 May 19 06:50 2014_10_12_000000_create_users_table.php
-rw-rw-r-- 1 appdev appdev 683 Jun 11 20:56 2014_10_12_100000_create_password_resets_table.php
-rw-rw-r-- 1 appdev appdev 774 May 19 06:50 2019_08_19_000000_create_failed_jobs_table.php

特にカスタマイズするテーブルがなければ、 .env または config/database.php が適切に設定されていることを確認し、マイグレーションを実行します。

$ php artisan migrate

この後はユーザー登録 → ログイン確認をすれば良いでしょう。

Fin❤︎

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6