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