Skip to content

Class api-v1 does not exist #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Dec 5, 2016 · 8 comments
Closed

Class api-v1 does not exist #32

ghost opened this issue Dec 5, 2016 · 8 comments

Comments

@ghost
Copy link

ghost commented Dec 5, 2016

Hi, I'm getting this error for some reason while trying to access the index route of a model.

ReflectionException in Container.php line 749:
Class api-v1 does not exist

I'm using laravel 5.3 and the routes are set up differently compared to the demo project.

@lindyhopchris
Copy link
Member

Hi! Bit difficult to diagnose based on what you've put, but I strongly suspect that you've got a middleware referenced as api-v1, but as you haven't registered anything on your HTTP Kernel for that name, it's trying to instantiate a class via the container instead.

The demo app use of api-v1 is a reference to a middleware group defined here:
https://github.com/cloudcreativity/demo-laravel-json-api/blob/master/app/Http/Kernel.php#L50

You can see that the group includes the JSON API middleware which is json-api:v1, with the v1 part of that referencing the v1 definition in the JSON API config file here:
https://github.com/cloudcreativity/demo-laravel-json-api/blob/master/config/json-api.php#L51

Does that help?

@ghost
Copy link
Author

ghost commented Dec 5, 2016

That was it! Thanks a lot! Altho I couldn't find anywhere in the wiki something related to that, during the configuration/installation.

@ghost ghost closed this as completed Dec 5, 2016
@lindyhopchris
Copy link
Member

Yeah, I need to write the wiki - haven't had time yet.

@roberttolton
Copy link

I think I'm having a similar issue, except mine says:

ReflectionException in Container.php line 749:
Class api does not exist

So it's trying to find api somewhere and failing, but I've not got anything defined as just api:

/routes/api.php

Route::group( [
    'middleware' => [ 'api-v1', 'cors', 'jwt.response_override' ],
    'namespace' => 'Api',
    'prefix' => 'v1',
    'as' => 'api-v1::'
], function () {
    JsonApi::resource( 'posts' );
} );

Kernel.php (middleware groups):

'api-v1' => [
    'json-api:v1',
    CheckForMaintenanceMode::class,
    'throttle:60,1',
    'bindings',
],

json-api.php:

'namespaces' => [
    'v1' => [
        'url-prefix' => '/api/v1',
        'supported-ext' => null,
        'paging' => [
            'page' => null,
            'per-page' => null,
        ],
        'paging-meta' => [
            'current-page' => null,
            'per-page' => null,
            'first-item' => null,
            'last-item' => null,
            'total' => null,
            'last-page' => null,
        ],
    ],
],

I think that Laravel 5.3, by using the /routes/api.php file is trying to automatically apply the now re-named api middleware group?

@lindyhopchris
Copy link
Member

@roberttolton what's in your RouteServiceProvider?

@roberttolton
Copy link

@lindyhopchris Ah, indeed, it's the below:

    protected function mapApiRoutes()
    {
        Route::group([
            'middleware' => 'api',
            'namespace' => $this->namespace,
            'prefix' => 'api',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

@roberttolton
Copy link

Should I change the RouteServiceProvider or leave it the way I have? Just two ways of doing the same I guess, but I wonder what your thoughts are.

@lindyhopchris
Copy link
Member

Totally up to you. If you only have one api, then probably just do all the JSON API stuff under the api middleware group. If you have multiple API definitions, I normally have a middleware group for each.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants