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) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Project\Role\Repositories\Presenter\LabelPresenter::class) ->$function(); } $labels = $this->repository->paginate(); return $this->response->setMetaTitle(trans('role::label.names')) ->view('role::label.index', true) ->data(compact('labels', 'view')) ->output(); } /** * Display label. * * @param Request $request * @param Model $label * * @return Response */ public function show(LabelRequest $request, Label $label) { if ($label->exists) { $view = 'role::label.show'; } else { $view = 'role::label.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('role::label.name')) ->data(compact('label')) ->view($view, true) ->output(); } /** * Show the form for creating a new label. * * @param Request $request * * @return Response */ public function create(LabelRequest $request) { $label = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('role::label.name')) ->view('role::label.create', true) ->data(compact('label')) ->output(); } /** * Create new label. * * @param Request $request * * @return Response */ public function store(LabelRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $label = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('role::label.name')])) ->code(204) ->status('success') ->url(guard_url('role/label/' . $label->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/role/label')) ->redirect(); } } /** * Show label for editing. * * @param Request $request * @param Model $label * * @return Response */ public function edit(LabelRequest $request, Label $label) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('role::label.name')) ->view('role::label.edit', true) ->data(compact('label')) ->output(); } /** * Update the label. * * @param Request $request * @param Model $label * * @return Response */ public function update(LabelRequest $request, Label $label) { try { $attributes = $request->all(); $label->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('role::label.name')])) ->code(204) ->status('success') ->url(guard_url('role/label/' . $label->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('role/label/' . $label->getRouteKey())) ->redirect(); } } /** * Remove the label. * * @param Model $label * * @return Response */ public function destroy(LabelRequest $request, Label $label) { try { $label->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('role::label.name')])) ->code(202) ->status('success') ->url(guard_url('role/label/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('role/label/' . $label->getRouteKey())) ->redirect(); } } /** * Remove multiple label. * * @param Model $label * * @return Response */ public function delete(LabelRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('role::label.name')])) ->status("success") ->code(202) ->url(guard_url('role/label')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/role/label')) ->redirect(); } } /** * Restore deleted labels. * * @param Model $label * * @return Response */ public function restore(LabelRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('role::label.name')])) ->status("success") ->code(202) ->url(guard_url('/role/label')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/role/label/')) ->redirect(); } } }