query('q')); $agents = $this->search($q)->with('groups:id,display_name')->paginate(25)->withQueryString(); $resolved = $agents->getCollection()->mapWithKeys(fn ($a) => [$a->id => $builder->templateFor($a)?->name]); return view('admin.agents.index', compact('agents', 'resolved', 'q')); } public function show(DirectoryUser $agent, SignatureBuilder $builder): View { $this->ensureTenant($agent); return view('admin.agents.show', [ 'agent' => $agent->load('groups:id,display_name'), 'template' => $builder->templateFor($agent), 'full' => $builder->build($agent, 'new'), 'reply' => $builder->build($agent, 'reply'), ]); } /** Autocomplétion pour le choix de l'agent d'aperçu. */ public function lookup(Request $request): JsonResponse { $q = trim((string) $request->query('q')); abort_if(mb_strlen($q) < 2, 422); return response()->json($this->search($q)->limit(15)->get()->map(fn ($a) => [ 'id' => $a->id, 'label' => trim($a->display_name.' — '.$a->mail), ])); } private function search(string $q) { return DirectoryUser::where('tenant_id', $this->tenantId()) ->where('account_enabled', true) ->when($q !== '', fn ($query) => $query->where(fn ($w) => $w ->where('display_name', 'like', "%{$q}%") ->orWhere('mail', 'like', "%{$q}%") ->orWhere('department', 'like', "%{$q}%"))) ->orderBy('display_name'); } }