staffIdentity($request); abort_unless($clients->ready(), 503); abort_unless($clients->canRead($actor), 403); $filters = $request->validate(['search' => 'nullable|string|max:180', 'page' => 'nullable|integer|min:1']); $query = BusinessClient::query()->where('tenant_id', $actor->tenant_id) ->select(['id', 'client_key', 'code', 'name', 'tax_number', 'address', 'email', 'active', 'version']); if (trim($filters['search'] ?? '') !== '') { $query->where(fn ($q) => $q->where('name', 'like', '%'.$filters['search'].'%')->orWhere('code', 'like', '%'.$filters['search'].'%')); } Inertia::encryptHistory(); $response = Inertia::render('company/clients', ['clients' => $query->orderBy('name')->paginate(20)->withQueryString(), 'filters' => $filters, 'canManage' => $clients->canManage($actor)])->toResponse($request); $response->headers->set('Cache-Control', 'private, no-store, max-age=0'); return $response; } public function store(Request $request, BusinessClients $clients): Response { $clients->save($this->staffIdentity($request), null, $request->all()); return redirect('/empresa/clientes')->with('success', 'Cliente registado.'); } public function update(Request $request, int $client, BusinessClients $clients): Response { $clients->save($this->staffIdentity($request), $client, $request->all()); return redirect('/empresa/clientes')->with('success', 'Cliente actualizado; os processos anteriores conservam a sua identificação original.'); } }