Files
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

94 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Cadastro\Localizacao;
use App\Http\Controllers\Controller;
use App\Http\Requests\Cadastro\Localizacao\BairroRequest;
use App\Models\Cadastro\Localizacao\Bairro;
use Illuminate\Http\Response;
class BairroController extends Controller
{
protected $modulo = 'cadastro';
protected $funcionalidade = 'bairro';
public function datatable()
{
$bairros = Bairro::with([]);
return datatables()->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();
}
}