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) { return $this->repository ->setPresenter(\Beegees\Raisen\Repositories\Presenter\OfficePresenter::class) ->paginate(); } /** * Display office. * * @param Request $request * @param Model $office * * @return Response */ public function show(OfficeRequest $request, Office $office) { return $office->setPresenter(\Beegees\Raisen\Repositories\Presenter\OfficeListPresenter::class); ; } /** * Create new office. * * @param Request $request * * @return Response */ public function store(OfficeRequest $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('raisen::office.name')]); $code = 204; $status = 'success'; $url = guard_url('raisen/office/' . $office->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('raisen/office'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the office. * * @param Request $request * @param Model $office * * @return Response */ public function update(OfficeRequest $request, Office $office) { try { $data = $request->all(); $office->update($data); $message = trans('messages.success.updated', ['Module' => trans('raisen::office.name')]); $code = 204; $status = 'success'; $url = guard_url('raisen/office/' . $office->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('raisen/office/' . $office->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the office. * * @param Model $office * * @return Response */ public function destroy(OfficeRequest $request, Office $office) { try { $office->delete(); $message = trans('messages.success.deleted', ['Module' => trans('raisen::office.name')]); $code = 202; $status = 'success'; $url = guard_url('raisen/office/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('raisen/office/' . $office->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); } }