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