query('q', '')); $investigations = collect(); $targets = collect(); if ($query !== '') { $investigations = Investigation::query() ->accessibleBy($request->user()) ->where('name', 'like', "%{$query}%") ->orderBy('name') ->get(); $targets = Target::query() ->whereHas('investigation', fn ($q) => $q->accessibleBy($request->user())) ->where('value', 'like', "%{$query}%") ->with('investigation') ->orderBy('value') ->limit(100) ->get(); } return view('search.index', [ 'query' => $query, 'investigations' => $investigations, 'targets' => $targets, ]); } }