Skip to main content

Configure routes

You can configure routes to create a CRUD in a simple way.

API CRUD

NameContent
moduleName of the module to use
prefixPrefix used for the route name
controllerName of the controller method to use
middlewareif not set up middleware, auth:api will be the default
customRoutesAllows the addition of customizable routes with the concatenated parent prefix. For example, by adding the route /icommerce/v3/products/sync, a custom route is created that extends from the parent prefix /products.

CustomRoutes

NameContent
methodAPI method
pathPrefix used for the route name
usesName of the controller method to use
middlewareif not set up middleware, auth:api will be the default
<?php

use Illuminate\Routing\Router;

$router->group(['prefix' => '/icommerce/v3'/*,'middleware' => ['auth:api']*/], function (Router $router) {
//====== OPTION TYPES - STATIC
$router->apiCrud([
'module' => 'icommerce',
'prefix' => 'option-types',
'staticEntity' => 'Modules\Icommerce\Entities\OptionType'
]);

$router->apiCrud([
'module' => 'icommerce',
'prefix' => 'products',
'controller' => 'ProductApiController',
//'middleware' => ['create' => [], 'index' => [], 'show' => [], 'update' => [], 'delete' => [], 'restore' => []]
'customRoutes' => [
['method' => 'post', 'path' => '/generate-spread-sheet', 'uses' => 'generateSpreadSheet', 'middleware' => []],
['method' => 'post', 'path' => '/sync', 'uses' => 'sync']
]
]);
});