'Target class LogoutController does not exist yet it does [closed]

I'm using Laravel 9

When I click on a link with the route /logout I get the following error: Target class [App\Http\Controllers\LogoutController] does not exist. Yet it does exist and the file is there. The file path to LogoutController.php is app/Http/Controllers/Auth/LogoutController.php

If I do a refresh I get a different error: The GET method is not supported for this route. Supported methods: POST. But the method is POST not GET. Here is my web.php line for the route and the class is imported using use App\Http\Controllers\Auth\LogoutController; :

Route::post('/logout', [LogoutController::class, 'logout_user'])->name('logout');

Here is my LogoutController in the Auth directory

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LogoutController extends Controller
{
    public function logout_user()
    {
        auth()->logout();
    }
}

Here is the link for the route:

        <li>
          <form action="{{route('logout')}}" method="POST">
          @csrf
          <button>Logout</button>
          </form>
        </li>

All the other routes that are the same work why is this one not working? Help to fix is appreciated.



Solution 1:[1]

I think you forget to import the class in your route. e.g use App\Http\Controllers\LogoutController;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ork Sophanin