Shulz
Shulz

Reputation: 625

Laravel Dingo class does not exist

I have code on api.php thats using a Dingo function and I am having trouble calling the controller because it always state that Controller is not found even though in their documentation it clearly has specified that I have to put the full path of the controller in which what is I have done.

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

// use Dingo\Api\Contract\Http\Request;
// use Dingo\Api\Facade\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$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\\Api\Controllers\\TestController@index');
    $api->get('hi','App\\Http\\Controllers\\TestController@index');
});

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

File locations: DingoImg

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

What do you think I am missing here?

Upvotes: 0

Views: 649

Answers (1)

Shulz
Shulz

Reputation: 625

Casing really does matter when referencing files. I just found this out recently.

Inside hello route

namespace app\Api\Controllers;

use Dingo\Api\Http\Request;
use app\Http\Controllers\Controller;

class TestController extends Controller
{
    public function index(Request $request)
    {
        return "hi";
    }
}

Have to change the app\Http\.. to App\Http\...
Also did the same on Api.php Controllers Path
Just a reminder so when you try to use "Copy relative path" on vscode try to watch out of the naming convention.

Upvotes: 0

Related Questions