This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Localizacao\LoteamentoRequest;
|
||||
use App\Models\Cadastro\Localizacao\Loteamento;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class LoteamentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'loteamento';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$loteamentos = Loteamento::with([]);
|
||||
|
||||
return datatables()->of($loteamentos)->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamentos = $this->get(Loteamento::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($loteamentos, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(LoteamentoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = Loteamento::create($this->getParams($request));
|
||||
|
||||
return response()->json($loteamento, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Loteamento::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = Loteamento::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'nome' => $loteamento->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(LoteamentoRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = tap(Loteamento::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($loteamento->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'nome' => mb_strtoupper($request->nome)
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Loteamento::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$loteamentos = Loteamento::with([]);
|
||||
|
||||
return datatables()->of($loteamentos)->toJson();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user