Target class [App\Http\Controllers\LoginController] does not exist
Solution 1
If you didn't move the controller from his default location, is inside the Auth folder, in the controller folder (app/Http/Controllers/Auth) So as your error Target class [App\Http\Controllers\LoginController] does not exist it's searching for the controller in the Controllers folders but not in the Auth subfolder, so The route is wrong.
Route::post('/index/logout','LoginController@postlogout')->name('postlogout');
should be
Route::post('/index/logout','Auth\LoginController@postlogout')->name('postlogout');
Best Regards.
Solution 2
If you did not create the controller with the artisan command, delete it and create it with the php artisan create:controller LoginController command. This should get the problem resolved.
Solution 3
I'm not sure if this is the default in Laravel 6, but the LoginController
is likely under the Auth
folder/namespace`:
app
- Http
-- Controllers
--- Auth
---- LoginController.php
...
In this case, you need to reference the namespace in your routes:
Route::middleware('auth')->group(function () {
Route::post('/index/dashboard/', 'Auth\LoginController@postlogin')->name('postlogin');
Route::post('/index/logout', 'Auth\LoginController@postlogout')->name('postlogout');
});
Solution 4
In your web.php file check all namespace passed, if their directory root is passed correctly or not.
in the upper part of web.php file you need to make sure of each controller root.
Such as you are using LoginController so you must pass use App\Http\Controllers\LoginController;
or use App\Http\Controllers\Controller\LoginController;
according to your Http\Controller project structure
Solution 5
Can you check the namespace of the controller
namespace App\Http\Controllers\Auth;
class LoginController extends Controller
Mubashir
Updated on July 05, 2022Comments
-
Mubashir almost 2 years
Laravel 6.x. I'm creating custom multi-authentication Panels(Staff,Student,Admin) from Single Login Page.Error already mentioned in the title. also without using php artisan ui bootstrap --auth. Web.php file.
Route::get('/index/sign-in', function () { return view('log-in'); }); Route::get('/index/admin', function () { return view('admin-dashboard'); }); Route::get('/index/student', function () { return view('student-dashboard'); }); Route::get('/index/staff', function () { return view('faculty-dashboard'); }); Route::middleware('auth')->group(function () { Route::post('/index/dashboard/','LoginController@postlogin')->name('postlogin'); Route::post('/index/logout','LoginController@postlogout')->name('postlogout'); });
LoginController.php file
public function postlogout() { auth()->logout(); //session()->flash('message', 'Some goodbye message'); return redirect('/index/sign-in/'); } public function postlogin() { $role=(Auth::user())->user_role; if ($role=='admin'){ return 'index/admin'; } elseif ($role=='staff'){ return 'index/staff'; } elseif ($role=='student'){ return 'index/student'; }else return 'index/sign-in'; } }
-
George Hanson about 4 yearsCan you share the full file path of your
LoginController
? -
Dino Numić about 4 yearsIt could be App\Http\Controllers\Auth
-
Mubashir about 4 years
-
-
Salman about 4 yearsif your login controller is inside auth folder then it'll be the same namespace else if it's not inside the folder then it'll be only
namespace App\Http\Controllers