get('q', ''); $groups = Group::query() ->with('organization') ->where('name', 'like', "%{$query}%") ->orderBy('name') ->limit(50) ->get() ->map(function($group) { return [ 'id' => $group->id, 'text' => $group->name . ($group->organization ? " ({$group->organization->name})" : ' (Общая)'), ]; }); return response()->json($groups); } }