dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

Target class does not exist (Controller not found) #1757

Closed jamols09 closed 3 years ago

jamols09 commented 3 years ago
Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 7.x
Package version 3.x.y
PHP version 7.3.18

Actual Behaviour

Whenever I try to load a class it will always display an error that Target Class is not found even I have specified the exact location of the file.

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {

    // This Will Work
    // $api->get('hello', function() {
    //     return "hi";
    // });

    //Will not work
    $api->get('hello', 'app\Http\Controllers\TestController@index');
    // $api->get('hi','app\Api\Controllers\TestController@index');
});

Error Message: message: "Target class [app\Http\Controllers\TestController] does not exist.", status_code: 500,

Screenshot of the File location image

Expected Behaviour

In the TestController it should only display a "hi" text. However I can only display the "hi" text if I write in on the route api.php

Steps to Reproduce

Possible Solutions

Not sure

jamols09 commented 3 years ago

Found the Issue

On my route 'hello' the name of path Should have a capitalized first letter. App\Http\Controller\.. instead of app\Http\Controller\..

specialtactics commented 3 years ago

Glad you solved it!