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