repository = $page; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Youssef\Newcm\Repositories\Criteria\PageResourceCriteria::class); } /** * Display a list of page. * * @return Response */ public function index(PageRequest $request) { return $this->repository ->setPresenter(\Youssef\Newcm\Repositories\Presenter\PagePresenter::class) ->paginate(); } /** * Display page. * * @param Request $request * @param Model $page * * @return Response */ public function show(PageRequest $request, Page $page) { return $page->setPresenter(\Youssef\Newcm\Repositories\Presenter\PageListPresenter::class); ; } /** * Create new page. * * @param Request $request * * @return Response */ public function store(PageRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('newcm::page.name')]); $code = 204; $status = 'success'; $url = guard_url('newcm/page/' . $page->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('newcm/page'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the page. * * @param Request $request * @param Model $page * * @return Response */ public function update(PageRequest $request, Page $page) { try { $data = $request->all(); $page->update($data); $message = trans('messages.success.updated', ['Module' => trans('newcm::page.name')]); $code = 204; $status = 'success'; $url = guard_url('newcm/page/' . $page->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('newcm/page/' . $page->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the page. * * @param Model $page * * @return Response */ public function destroy(PageRequest $request, Page $page) { try { $page->delete(); $message = trans('messages.success.deleted', ['Module' => trans('newcm::page.name')]); $code = 202; $status = 'success'; $url = guard_url('newcm/page/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('newcm/page/' . $page->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }