query) < 2) { $this->results = []; $this->showResults = false; return; } $this->search(); $this->showResults = true; } public function search(): void { $q = $this->query; $projectIds = Auth::user()->projects()->pluck('id'); $features = Feature::search($q) ->where('project_id', $projectIds) ->take($this->limit) ->get() ->map(function ($feature) { return [ 'type' => 'feature', 'type_label' => 'Elemento', 'id' => $feature->id, 'title' => $feature->name, 'subtitle' => $feature->layer?->phase?->name ?? 'Sin fase', 'url' => route('projects.map', $feature->layer?->phase?->project_id).'?feature='.$feature->id, 'icon' => 'square-2-stack', 'color' => 'blue', ]; }); $issues = Issue::search($q) ->where('project_id', $projectIds) ->take($this->limit) ->get() ->map(function ($issue) { return [ 'type' => 'issue', 'type_label' => 'Incidencia', 'id' => $issue->id, 'title' => $issue->title, 'subtitle' => $issue->project?->name ?? 'Sin proyecto', 'url' => route('projects.issues.show', [$issue->project_id, $issue->id]), 'icon' => 'exclamation-triangle', 'color' => 'red', ]; }); $tasks = Task::search($q) ->where('project_id', $projectIds) ->take($this->limit) ->get() ->map(function ($task) { return [ 'type' => 'task', 'type_label' => 'Tarea', 'id' => $task->id, 'title' => $task->title, 'subtitle' => $task->project?->name ?? 'Sin proyecto', 'url' => route('projects.tasks.show', [$task->project_id, $task->id]), 'icon' => 'clipboard-document-check', 'color' => 'green', ]; }); $inspections = Inspection::search($q) ->where('project_id', $projectIds) ->take($this->limit) ->get() ->map(function ($inspection) { return [ 'type' => 'inspection', 'type_label' => 'Inspección', 'id' => $inspection->id, 'title' => $inspection->feature?->name ?? 'Inspección', 'subtitle' => $inspection->template?->name ?? 'Sin template', 'url' => route('projects.map', $inspection->project_id).'?inspection='.$inspection->id, 'icon' => 'magnifying-glass', 'color' => 'purple', ]; }); $this->results = $features ->concat($issues) ->concat($tasks) ->concat($inspections) ->sortBy(fn ($r) => $r['type']) ->take($this->limit * 4) ->values() ->toArray(); } #[On('close-search-results')] public function hideResults(): void { $this->showResults = false; } public function clearSearch(): void { $this->query = ''; $this->results = []; $this->showResults = false; } public function render() { return view('livewire.common.global-search'); } }