middleware(function ($request, $next) { $this->form = BuildingForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.location.modules'), 'location', guard_url('location')); return $next($request); }); } /** * Display a list of building. * * @return Response */ public function index(BuildingResourceRequest $request) { $request = $request->all(); $page = BuildingActions::run('paginate', $request); $data = new BuildingsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('location::building.names')) ->view('location::building.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display building. * * @param Request $request * @param Model $building * * @return Response */ public function show(BuildingResourceRequest $request, Building $model) { $form = $this->form; $modules = $this->modules; $data = new BuildingResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('location::building.name')) ->data(compact('data', 'form', 'modules')) ->view('location::building.show') ->output(); } /** * Show the form for creating a new building. * * @param Request $request * * @return Response */ public function create(BuildingResourceRequest $request, Building $model) { $form = $this->form; $modules = $this->modules; $data = new BuildingResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('location::building.name')) ->view('location::building.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new building. * * @param Request $request * * @return Response */ public function store(BuildingResourceRequest $request, Building $model) { try { $request = $request->all(); $model = BuildingAction::run('store', $model, $request); $data = new BuildingResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('location::building.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('location/building/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/location/building')) ->redirect(); } } /** * Show building for editing. * * @param Request $request * @param Model $building * * @return Response */ public function edit(BuildingResourceRequest $request, Building $model) { $form = $this->form; $modules = $this->modules; $data = new BuildingResource($model); // return view('location::building.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('location::building.name')) ->view('location::building.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the building. * * @param Request $request * @param Model $building * * @return Response */ public function update(BuildingResourceRequest $request, Building $model) { try { $request = $request->all(); $model = BuildingAction::run('update', $model, $request); $data = new BuildingResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('location::building.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('location/building/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/building/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the building. * * @param Model $building * * @return Response */ public function destroy(BuildingResourceRequest $request, Building $model) { try { $request = $request->all(); $model = BuildingAction::run('destroy', $model, $request); $data = new BuildingResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('location::building.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('location/building/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('location/building/' . $model->getRouteKey())) ->redirect(); } } }