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