Skip to content

Commit

Permalink
Creating api routes for Page resource
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Sep 10, 2017
1 parent 68a2cb6 commit 4922747
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Modules/Page/Http/Controllers/Api/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Modules\Page\Http\Controllers\Api;

use Illuminate\Routing\Controller;
use Modules\Page\Entities\Page;
use Modules\Page\Repositories\PageRepository;

class PageController extends Controller
{
/**
* @var PageRepository
*/
private $page;

public function __construct(PageRepository $page)
{
$this->page = $page;
}

public function destroy($page)
{
$this->page->destroy($page);

return response()->json([
'errors' => false,
'message' => trans('page::messages.page deleted'),
]);
}
}
16 changes: 16 additions & 0 deletions Modules/Page/Http/apiRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('page', function ($id) {
return app(\Modules\Page\Repositories\PageRepository::class)->find($id);
});

$router->group(['prefix' => '/page'], function (Router $router) {
$router->delete('pages/{page}', [
'as' => 'api.page.page.destroy',
'uses' => 'PageController@destroy',
'middleware' => 'token-can:page.pages.destroy',
]);
});
2 changes: 1 addition & 1 deletion Modules/Page/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected function getBackendRoute()
*/
protected function getApiRoute()
{
return false;
return __DIR__ . '/../Http/apiRoutes.php';
}
}

0 comments on commit 4922747

Please sign in to comment.