of($bairros)->skipTotalRecords()->toJson(); } public function index() { $this->auth(__FUNCTION__); $bairros = $this->get(Bairro::class)->orderBy('nome')->get(); return response()->json($bairros, Response::HTTP_OK); } public function store(BairroRequest $request) { $this->auth(__FUNCTION__); $bairro = Bairro::create($this->getParams($request)); return response()->json($bairro, Response::HTTP_CREATED); } public function show($id) { $this->auth(__FUNCTION__); return response()->json($this->get(Bairro::class, $id), Response::HTTP_OK); } public function edit($id) { $this->auth(__FUNCTION__); $bairro = Bairro::findOrFail($id); return response()->json( [ 'model' => [ 'nome' => $bairro->nome, ], ], Response::HTTP_OK ); } public function update(BairroRequest $request, $id) { $this->auth(__FUNCTION__); $bairro = tap(Bairro::findOrFail($id))->update($this->getParams($request)); return response()->json($bairro->fresh(), Response::HTTP_OK); } private function getParams($request) { return [ 'nome' => mb_strtoupper($request->nome) ]; } public function destroy($id) { $this->auth(__FUNCTION__); Bairro::findOrFail($id)->delete(); return response()->json(null, Response::HTTP_NO_CONTENT); } public function autocomplete() { $bairros = Bairro::with([]); return datatables()->of($bairros)->toJson(); } }