repository = $offplan; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Offplans\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\Offplans\Repositories\Presenter\OffplanPresenter::class) ->$function(); } $offplans = $this->repository->paginate(); return $this->response->setMetaTitle(trans('offplans::offplan.names')) ->view('offplans::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 = 'offplans::offplan.show'; } else { $view = 'offplans::offplan.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('offplans::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('offplans::offplan.name')) ->view('offplans::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('offplans::offplan.name')])) ->code(204) ->status('success') ->url(guard_url('offplans/offplan/' . $offplan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/offplans/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('offplans::offplan.name')) ->view('offplans::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('offplans::offplan.name')])) ->code(204) ->status('success') ->url(guard_url('offplans/offplan/' . $offplan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('offplans/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('offplans::offplan.name')])) ->code(202) ->status('success') ->url(guard_url('offplans/offplan/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('offplans/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('offplans::offplan.name')])) ->status("success") ->code(202) ->url(guard_url('offplans/offplan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/offplans/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('offplans::offplan.name')])) ->status("success") ->code(202) ->url(guard_url('/offplans/offplan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/offplans/offplan/')) ->redirect(); } } }