search

Home  >  Q&A  >  body text

Laravel adds Api namespace

You can see that a new api folder has been added to the laravel project

This folder is used for the api interface for external development

The path under the api folder is

api\V1\UserController.php

And when defining routes in routes.php

$api = app('api.router');
$api->version('v1', function ($api) {
    $api->get('users/{id}', 'Api\V1\UserController@show');  
});

The class of this Api\V1\UserController cannot be found

Where do I need to configure the Api namespace? Because the api directory is not registered in laravel at all

Where to configure?

PHP中文网PHP中文网2830 days ago679

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 16:57:57

    composer.json

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 16:57:57

    php$api->version('v1', ['namespace' => 'Api\V1'], function ($api) {
        $api->get('users/{id}', 'UserController@show');
    });
    

    reply
    0
  • Cancelreply