44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Intranet;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Intranet\Municipio;
|
|
use Illuminate\Http\Response;
|
|
|
|
class MunicipioController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$municipios = $this->get(Municipio::class)
|
|
->where($this->getWhereFromQueryString(['estado_id', 'nome']))
|
|
->orderBy('nome')
|
|
->get();
|
|
|
|
return response()->json($municipios, Response::HTTP_OK);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
return response()->json($this->get(Municipio::class, $id), Response::HTTP_OK);
|
|
}
|
|
|
|
|
|
public function autocomplete()
|
|
{
|
|
$municipios = Municipio::with([]);
|
|
|
|
if (is_numeric(request()->estado_id)) {
|
|
|
|
$municipios->where('estado_id', request()->estado_id);
|
|
}
|
|
|
|
if (is_numeric(request()->not_municipio_id)) {
|
|
|
|
$municipios->where('id', '<>', request()->not_municipio_id);
|
|
}
|
|
|
|
return datatables()->of($municipios)->toJson();
|
|
}
|
|
}
|