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