Kevin Powell - CommunityKP-C
Kevin Powell - Community16mo ago
11 replies
sebin

Laravel 11 Target class does not exist.

Hi guys I just wanna ask what are the solution I can try to fix this error?


When Im clicing on my log out href on my dashboard, it also direct me to the url of
localhost:8000/establishment/logout instead of
localhost:8000/establishment/login and give me the error of Target class [establishment] does not exist.
All my middleware, controller, route, auth.php are correct I tried GPT still cant solved the problem.


Tech Laravel 11 Breeze, React
Important Codes Snippet below






Dashboard.jsx
<a href={route('establishment.logout')}
method="get"
as="button">
Log out
</a>


web.php
Route::prefix('establishment')->group(function() {
    Route::get('/login', [EstablishmentController::class, 'EstablishmentIndex'])->name('establishment.login');
    Route::post('/login/user', [EstablishmentController::class, 'EstablishmentLogin'])->name('establishment.login.user');
    Route::get('logout', [EstablishmentController::class, 'EstablishmentLogout'])->name('establishment.logout')->middleware('establishment');
   
});



Establishment.php
 public function EstablishmentLogout(){
        Auth::guard('establishment')->logout();
        return redirect()->route('establishment.login')->with('loggedout', 'Logged out successfully');
     }


EstablishmentMiddleware
 public function handle(Request $request, Closure $next): Response
     {
        if (!Auth::guard('establishment')->check()){
             return redirect()->route('establishment.login')->with('Error','Please login first');
        }

        return $next($request);

   
     }
image.png
Was this page helpful?