LoginSignup
3
2

More than 5 years have passed since last update.

Laravel5.5で認証(login)機能を追加する

Last updated at Posted at 2018-07-22

login機能を設定します。

コマンドラインで以下を入力

php artisan make:auth

以下が作成される。
LoginController.php
RegisterController.php
ResetPasswordController.php

マイグレーションする

php artisan migrate

ログイン後でないとアクセスできないように設定

\app\Http\Controllers\ArticleController.php

    public function __construct()
    {
        $this->middleware('auth');
    }

ログインした先のパスを設定

\app\Http\Controllers\Auth\LoginController.php
    protected $redirectTo = '/article';

以下にも同じように設定
\app\Http\Controllers\Auth\RegisterController.php
\app\Http\Controllers\Auth\ResetPasswordController.php

ちなみにこんな感じでログインしているユーザのidが取れます。

 $login_use_id = Auth::id();

参考
Laravel 5.5 認証
https://readouble.com/laravel/5.5/ja/authentication.html

3
2
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
3
2