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