Creating api routes for Page resource

parent 68a2cb6c
<?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'),
]);
}
}
<?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',
]);
});
......@@ -33,6 +33,6 @@ class RouteServiceProvider extends CoreRoutingServiceProvider
*/
protected function getApiRoute()
{
return false;
return __DIR__ . '/../Http/apiRoutes.php';
}
}
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