form = SublocationForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.location.modules'), 'location', guard_url('location')); } /** * Display a list of sublocation. * * @return Response */ public function index(SublocationResourceRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Sublocation::pushScope(new RequestScope()) ->pushScope(new SublocationResourceScope()) ->paginate($pageLimit); $data = new SublocationsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('location::sublocation.names')) ->view('location::sublocation.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display sublocation. * * @param Request $request * @param Model $sublocation * * @return Response */ public function show(SublocationResourceRequest $request, Sublocation $model) { $form = $this->form; $modules = $this->modules; $data = new SublocationResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('location::sublocation.name')) ->data(compact('data', 'form', 'modules')) ->view('location::sublocation.show') ->output(); } /** * Show the form for creating a new sublocation. * * @param Request $request * * @return Response */ public function create(SublocationResourceRequest $request, Sublocation $model) { $form = $this->form; $modules = $this->modules; $data = new SublocationResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('location::sublocation.name')) ->view('location::sublocation.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new sublocation. * * @param Request $request * * @return Response */ public function store(SublocationResourceRequest $request, Sublocation $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new SublocationResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('location::sublocation.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('location/sublocation/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/location/sublocation')) ->redirect(); } } /** * Show sublocation for editing. * * @param Request $request * @param Model $sublocation * * @return Response */ public function edit(SublocationResourceRequest $request, Sublocation $model) { $form = $this->form; $modules = $this->modules; $data = new SublocationResource($model); // return view('location::sublocation.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('location::sublocation.name')) ->view('location::sublocation.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the sublocation. * * @param Request $request * @param Model $sublocation * * @return Response */ public function update(SublocationResourceRequest $request, Sublocation $model) { try { $attributes = $request->all(); $model->update($attributes); $data = new SublocationResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('location::sublocation.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('location/sublocation/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/sublocation/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the sublocation. * * @param Model $sublocation * * @return Response */ public function destroy(SublocationResourceRequest $request, Sublocation $model) { try { $model->delete(); $data = new SublocationResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('location::sublocation.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('location/sublocation/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/sublocation/' . $model->getRouteKey())) ->redirect(); } } }