Create Api routes in Laravel 5.2

1

Because the file is not in this version and I mean routes/api.php . This version only includes a single file routes.php my problem is that I could define api routes in this version. I'm currently doing it in a web:

Route::get('/api/menus','Api\MenusController@index');

which is not even good, because in >route list is using the middleware web, therefore it works but it is not the right thing to do separation of both branches.

Then then ...

  

What can I do to configure the api routes?

    
asked by DoubleM 11.12.2018 в 19:25
source

1 answer

1

For that you have to modify the respective ServiceProvider and add another file of routes (although it can be solved in many ways):

RouteServiceProvider.php

<?php
...
class RouteServiceProvider ...
{
    ...

    public function map(Router $router)
    {
        $this->mapWebRoutes($router);

        // agregar esto
        $this->mapApiRoutes($router);
    }

    // agregar esto
    protected function mapApiRoutes(Router $router)
    {
        $router->group([
            'namespace' => 'App\Http\Controllers\Api', 'middleware' => 'api',
        ], function ($router) {
            require app_path('Http/api-routes.php');
        });
    }

    ...
}
    
answered by 11.12.2018 / 19:31
source