1
votes

Fresh laravel lumen 5.8 installed but controller name cannot be found in route

I created UserController in App\Http\Controllers\User

User Controller Content:

namespace App\Http\Controllers;

class UserController extends Controller {
   public function index() {
      return 'User list';
   }
}

Loaded in route:

$router->get('/user', 'User\UserController@index')

Error:

Class App\Http\Controllers\User\UserController does not exist

I also tried with absolute namespace App\Http\Controllers\User\UserController@index but it still doesn't work.

It works if I don't put UserController in User folder

2
Try changing namespace of the controller to namespace App\Http\Controllers\User;linuxartisan
I will convert it to an answer, you may mark it as accepted.linuxartisan

2 Answers

2
votes

Change your UserController's namespace to:

namespace App\Http\Controllers\User;

class UserController extends Controller
{
   // ...
}
1
votes

Try changing namespace of the controller to

namespace App\Http\Controllers\User;

class UserController extends Controller
{
   // ...
}