Search code examples
phplaraveldingo-api

Laravel dingo api not recognizing the method giving error Method [testing] does not exist


i have two routes

 1. $api->get('usersInfo','App\Http\Controllers\ApiController@usersInfo');
 2. $api->get("checkboxbriefs/tbbid/{tbbid}","App\Http\Controllers\
 ApiController@testing");

which i am using like this.

$api = app('Dingo\Api\Routing\Router');
$api->version('v1',function($api) {
$api->get('usersInfo','App\Http\Controllers\ApiController@usersInfo');
$api-    
>get("checkboxbriefs/tbbid/{tbbid}","App\Http\Controllers\
ApiController@testing");

}

I have added

'providers' => [
    Dingo\Api\Provider\LaravelServiceProvider::class
]

in providers.

have Also corrected config.

i am getting error in second route as :

"message":"Method [testing] does not exist.","status_code":500,"debug":

first route is working fine without any issue.


Solution

  • For anyone who is looking for solution of such problem.

    There is nothing wrong with the implementation try to go threw your code and find any error in controller there must be some.

    If you will create new controller with different name and place one function there, calling that function you will get variable value passed threw route.

    At least that is what happened in my case.

    I created new controller with different name containing only single function and it worked leaving me to assume there are some errors in my script, after editing everything worked fine.

    This kind of error comes up with Laravel5.* version while you have not called fully qualified class name. like I have called

    if (App::environment('local')) {
            ini_set('display_errors', E_ALL);
            error_reporting(1);
    

    }

    where I need to call bellow

    if (\App::environment('local')) {
                ini_set('display_errors', E_ALL);
                error_reporting(1);
     }
    

    Error Example {"message":"Class 'App\\Http\\Controllers\\App' not found","status_code":500}