repository = $hierarchy; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Survey\Organisation\Repositories\Criteria\HierarchyResourceCriteria::class); } /** * Display a list of hierarchy. * * @return Response */ public function index(HierarchyRequest $request) { return $this->repository ->setPresenter(\Survey\Organisation\Repositories\Presenter\HierarchyPresenter::class) ->paginate(); } /** * Display hierarchy. * * @param Request $request * @param Model $hierarchy * * @return Response */ public function show(HierarchyRequest $request, Hierarchy $hierarchy) { return $hierarchy->setPresenter(\Survey\Organisation\Repositories\Presenter\HierarchyListPresenter::class); ; } /** * Create new hierarchy. * * @param Request $request * * @return Response */ public function store(HierarchyRequest $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('organisation::hierarchy.name')]); $code = 204; $status = 'success'; $url = guard_url('organisation/hierarchy/' . $hierarchy->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('organisation/hierarchy'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the hierarchy. * * @param Request $request * @param Model $hierarchy * * @return Response */ public function update(HierarchyRequest $request, Hierarchy $hierarchy) { try { $data = $request->all(); $hierarchy->update($data); $message = trans('messages.success.updated', ['Module' => trans('organisation::hierarchy.name')]); $code = 204; $status = 'success'; $url = guard_url('organisation/hierarchy/' . $hierarchy->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('organisation/hierarchy/' . $hierarchy->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the hierarchy. * * @param Model $hierarchy * * @return Response */ public function destroy(HierarchyRequest $request, Hierarchy $hierarchy) { try { $hierarchy->delete(); $message = trans('messages.success.deleted', ['Module' => trans('organisation::hierarchy.name')]); $code = 202; $status = 'success'; $url = guard_url('organisation/hierarchy/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('organisation/hierarchy/' . $hierarchy->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); } }