Create route and controller to change page status

parent c6ea85c1
<?php
namespace Modules\Page\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Page\Repositories\PageRepository;
class UpdatePageStatusController extends Controller
{
/**
* @var PageRepository
*/
private $page;
public function __construct(PageRepository $page)
{
$this->page = $page;
}
public function __invoke(Request $request)
{
$pageIds = json_decode($request->get('pageIds'));
$this->handleAction($request->get('action'), $pageIds);
return response()->json(['errors' => false, 'message' => 'Pages were updated']);
}
private function handleAction(string $action, array $pageIds)
{
if ($action === 'mark-online') {
return $this->page->markMultipleAsOnlineInAllLocales($pageIds);
}
return $this->page->markMultipleAsOfflineInAllLocales($pageIds);
}
}
......@@ -18,6 +18,11 @@ $router->group(['prefix' => '/page', 'middleware' => ['api.token', 'auth.admin']
'uses' => 'PageController@indexServerSide',
'middleware' => 'token-can:page.pages.index',
]);
$router->get('mark-pages-status', [
'as' => 'api.page.page.mark-status',
'uses' => 'UpdatePageStatusController',
'middleware' => 'token-can:page.pages.edit',
]);
$router->delete('pages/{page}', [
'as' => 'api.page.page.destroy',
'uses' => 'PageController@destroy',
......
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