@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\PeopleRegistry;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PeopleRegistryController extends Controller
|
||||
{
|
||||
public function index(Request $request, PeopleRegistry $registry): Response
|
||||
{
|
||||
abort_unless($registry->canRead($request->user()), 403);
|
||||
$filter = $request->validate(['search' => 'nullable|string|max:100', 'status' => 'nullable|in:active,archived,all']);
|
||||
$ready = Schema::hasTable('people_registry');
|
||||
$records = null;
|
||||
if ($ready) {
|
||||
$query = $registry->visible($request->user());
|
||||
if (($filter['search'] ?? '') !== '') {
|
||||
$query->where(fn ($q) => $q->whereLike('name', '%'.$filter['search'].'%')->orWhereLike('reference', '%'.$filter['search'].'%'));
|
||||
}
|
||||
if (($filter['status'] ?? 'active') !== 'all') {
|
||||
$query->where('active', ($filter['status'] ?? 'active') === 'active');
|
||||
}
|
||||
$records = $query->orderBy('name')->orderBy('id')->paginate(15)->withQueryString()->through(fn ($row) => $registry->item($request->user(), $row));
|
||||
}
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('people/registry', ['ready' => $ready, 'canCreate' => $registry->canCreate($request->user()), 'records' => $records, 'filters' => $filter])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function save(Request $request, PeopleRegistry $registry, ?int $person = null): Response
|
||||
{
|
||||
abort_unless(Schema::hasTable('people_registry'), 503, 'Instalação do cadastro de pessoas pendente.');
|
||||
$record = $registry->execute($request->user(), $person, $request->all());
|
||||
|
||||
return redirect('/pessoas/cadastro?'.http_build_query(['search' => $record->reference, 'status' => 'all']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user