前提・実現したいこと
現在laravelでマルチログイン機能を作っています。
教員用のログイン、登録機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Target class [Professor\LoginController] does not exist.
route/web.php
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\Professor\LoginController; Auth::routes(); /* |-------------------------------------------------------------------------- | userログイン前 |-------------------------------------------------------------------------- | */ Route::get('/', function () { return view('welcome'); }); /* |-------------------------------------------------------------------------- | userログイン後 |-------------------------------------------------------------------------- | */ Route::group(['middleware'=> 'auth:user'], function(){ Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); }); /* |-------------------------------------------------------------------------- | professorログイン前 |-------------------------------------------------------------------------- | */ Auth::routes(); Route::group(['prefix' => 'professor'], function() { Route::get('/', function () { return redirect('home'); }); Route::get('/login', 'Professor\LoginController@showLoginForm')->name('professor.login'); Route::get('/login', [LoginController::class, 'showLoginForm'])->name('Professor.login'); Route::get('/register', 'Professor\LoginController@showRegisterForm')->name('professor.register'); Route::post('/login', 'Professor\LoginController@login'); }); /* |-------------------------------------------------------------------------- | professorログイン後 |-------------------------------------------------------------------------- | */ Route::group(['prefix' => 'professor', 'middleware' => 'auth:professor'], function() { Route::post('logout',[App\Http\Controllers\LoginController::class, 'logout'])->name('professor.logout'); Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); });
App/Http/Controllers/Professor/LoginController.php
<?php namespace App\Http\Controllers\Professor; use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller { use AuthenticatesUsers; /** * Where to redirect users after login. * * @var string */ protected $redirectTo = RouteServiceProvider::HOME; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest:professor')->except('logout'); } public function showLoginForm() { return view('professor.login'); } protected function guard() { return Auth::guard('professor'); } public function logout(Request $request) { // Auth::guard('professor')->logout(); $request->session()->flush(); $request->session()->regenerate(); return redirect('/professor/login'); } }
###App/Http/Controllers/Professor/HomeController.php
<?php namespace App\Http\Controllers\Professor; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class HomeController extends Controller { /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth:professor'); } /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { return view('professor:home'); } }
###config/auth.php
<?php return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change these defaults | as required, but they're a perfect start for most applications. | */ 'defaults' => [ 'guard' => 'user', 'passwords' => 'users', ], /* |-------------------------------------------------------------------------- | Authentication Guards |-------------------------------------------------------------------------- | | Next, you may define every authentication guard for your application. | Of course, a great default configuration has been defined for you | here which uses session storage and the Eloquent user provider. | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | Supported: "session", "token" | */ 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ], 'user' => [ 'driver' => 'session', 'provider' => 'users', ], 'professor' => [ //追加 'driver' => 'session', //追加 'provider' => 'professors', //追加 ], ], /* |-------------------------------------------------------------------------- | User Providers |-------------------------------------------------------------------------- | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | If you have multiple user tables or models you may configure multiple | sources which represent each model / table. These sources may then | be assigned to any extra authentication guards you have defined. | | Supported: "database", "eloquent" | */ 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'professors' => [ //追加 'driver' => 'eloquent', //追加 'model' => App\Models\Professor::class, //追加 ], // 'users' => [ // 'driver' => 'database', // 'table' => 'users', // ], ], /* |-------------------------------------------------------------------------- | Resetting Passwords |-------------------------------------------------------------------------- | | You may specify multiple password reset configurations if you have more | than one user table or model in the application and you want to have | separate password reset settings based on the specific user types. | | The expire time is the number of minutes that the reset token should be | considered valid. This security feature keeps tokens short-lived so | they have less time to be guessed. You may change this as needed. | */ 'passwords' => [ 'users' => [ 'provider' => 'users', 'table' => 'password_resets', 'expire' => 60, 'throttle' => 60, ], 'professors' => [ //追加 'provider' => 'professors', //追加 'table' => 'password_resets', //追加 'expire' => 60, //追加 ], ], /* |-------------------------------------------------------------------------- | Password Confirmation Timeout |-------------------------------------------------------------------------- | | Here you may define the amount of seconds before a password confirmation | times out and the user is prompted to re-enter their password via the | confirmation screen. By default, the timeout lasts for three hours. | */ 'password_timeout' => 10800, ];
試したこと
コントローラのnamespace、ルーティングのスペルなどチェックしましたが解決しませんでした。laravel 8.xからルーティングの記載方法が変わった事を考慮して書き換えてみましたが変化なかったです。
どこに原因があるか教えていただけたら嬉しいです。よろしくお願いします。
補足情報(FW/ツールのバージョンなど)
laravel 8.4.0
PHP 7.4.10
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。