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