5

I have been trying to implement a REST API using the Laravel 5 Dingo API package.

This is my routing code:

 $api->version('v1', function ($api) {
    $api->get('users/{id}', 'Api\V1\UsersController@show');
});

This is my error code:

{"message":"Class Api\\V1\\UsersController does not exist","code":-1,"status_code":500}

So, where should I place my controller file in order it finds the correct path for my controller ?

I placed the file in app/http/controllers/Api/V1/ directory but I'm still getting this kind of error.

I am using Dingo API 0.10 for Laravel.

perror
  • 7,071
  • 16
  • 58
  • 85
sabin adhikari
  • 225
  • 3
  • 14
  • Does your `UsersController` file have the correct namespace? I.e. does it have `namespace App\Http\Controllers\Api\V1` at the top of the file? – haakym Aug 10 '15 at 08:31
  • yes there is `namespace App\Http\Controllers\Api\V1` at the top the Userscontroller – sabin adhikari Aug 10 '15 at 09:21
  • The only other thing I could recommend with what I can see is to check for spelling mistakes and check you're following the docs properly: https://github.com/dingo/api/wiki/Creating-API-Endpoints If you can add more info to your question you may be able to get some more help. Maybe copy paste the output of `route:list` – haakym Aug 10 '15 at 10:18
  • 1
    Solved this problem my adding full path of the controller in the route `$api->get('users/{id}', 'App\Http\Controllers\Api\V1\UsersController@show');` – sabin adhikari Aug 11 '15 at 09:53
  • Glad you got a solution to your problem. You can add your answer if you like! – haakym Aug 11 '15 at 14:11

1 Answers1

7

By adding full path of the controller in the route

$api->get('users/{id}', 'App\Http\Controllers\Api\V1\UsersController@show');

will fix this error.

sabin adhikari
  • 225
  • 3
  • 14