【Laravel5.8】ログアウトのredirect先をカスタマイズしたい

Laravel5.8のmake:authで作成したログアウト機能で、redirect先をカスタマイズしたい際の方法です。


/magotaku/app/Http/Controllers/Auth/LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request; // 追加

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

   // 書き換え
    use AuthenticatesUsers {
        logout as performLogout;
    }

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
    
   // logoutファンクションを作成
    public function logout(Request $request)
    {
        $this->performLogout($request);
  // redirect先は人それぞれカスタマイズ
        return redirect('/home');
    }
}

以上です。

参考
qiita.com