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