form = DepartmentForm::setAttributes()->toArray(); $this->modules = $this->modules(config('litepci.department.modules'), 'department', guard_url('department')); $this->repository = $department; } /** * Display a list of department. * * @return Response */ public function index(DepartmentRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(DepartmentResourceFilter::class) ->setPresenter(DepartmentListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('department::department.names')) ->view('department::department.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display department. * * @param Request $request * @param Model $department * * @return Response */ public function show(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('department::department.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('department::department.show') ->output(); } /** * Show the form for creating a new department. * * @param Request $request *x * @return Response */ public function create(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('department::department.name')) ->view('department::department.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new department. * * @param Request $request * * @return Response */ public function store(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('department::department.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('department/department/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/department/department')) ->redirect(); } } /** * Show department for editing. * * @param Request $request * @param Model $department * * @return Response */ public function edit(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('department::department.name')) ->view('department::department.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the department. * * @param Request $request * @param Model $department * * @return Response */ public function update(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('department::department.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('department/department/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('department/department/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the department. * * @param Model $department * * @return Response */ public function destroy(DepartmentRequest $request, DepartmentRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('department::department.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('department/department/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('department/department/' . $repository->getRouteKey())) ->redirect(); } } }