Structuring api routes in route group

parent 3d14a920
......@@ -3,41 +3,42 @@
use Illuminate\Routing\Router;
/** @var Router $router */
$router->bind('role', function ($id) {
return app(\Modules\User\Repositories\RoleRepository::class)->find($id);
});
$router->group(['prefix' => '/user', 'middleware' => ['api.token', 'auth.admin']], function (Router $router) {
$router->get('roles', [
'as' => 'api.user.role.index',
'uses' => 'RoleController@index',
'middleware' => 'token-can:user.roles.index',
]);
$router->post('roles', [
'as' => 'api.user.role.store',
'uses' => 'RoleController@store',
'middleware' => 'token-can:user.roles.create',
]);
$router->post('roles/find/{role}', [
'as' => 'api.user.role.find',
'uses' => 'RoleController@find',
'middleware' => 'token-can:user.roles.edit',
]);
$router->post('roles/find-new', [
'as' => 'api.user.role.find-new',
'uses' => 'RoleController@findNew',
'middleware' => 'token-can:user.roles.edit',
]);
$router->post('roles/{role}/edit', [
'as' => 'api.user.role.update',
'uses' => 'RoleController@update',
'middleware' => 'token-can:user.roles.edit',
]);
$router->delete('roles/{role}', [
'as' => 'api.user.role.destroy',
'uses' => 'RoleController@destroy',
'middleware' => 'token-can:user.roles.destroy',
]);
$router->group(['prefix' => 'roles'], function (Router $router) {
$router->bind('role', function ($id) {
return app(\Modules\User\Repositories\RoleRepository::class)->find($id);
});
$router->get('/', [
'as' => 'api.user.role.index',
'uses' => 'RoleController@index',
'middleware' => 'token-can:user.roles.index',
]);
$router->post('/', [
'as' => 'api.user.role.store',
'uses' => 'RoleController@store',
'middleware' => 'token-can:user.roles.create',
]);
$router->post('find/{role}', [
'as' => 'api.user.role.find',
'uses' => 'RoleController@find',
'middleware' => 'token-can:user.roles.edit',
]);
$router->post('find-new', [
'as' => 'api.user.role.find-new',
'uses' => 'RoleController@findNew',
'middleware' => 'token-can:user.roles.edit',
]);
$router->post('{role}/edit', [
'as' => 'api.user.role.update',
'uses' => 'RoleController@update',
'middleware' => 'token-can:user.roles.edit',
]);
$router->delete('{role}', [
'as' => 'api.user.role.destroy',
'uses' => 'RoleController@destroy',
'middleware' => 'token-can:user.roles.destroy',
]);
});
$router->get('permissions', [
'as' => 'api.user.permissions.index',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment