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