$mentionedUsers * @return array */ public function get(string $body, array $mentionedUsers): array { $handles = array_values(array_diff($this->mentions->handles($body), array_keys($mentionedUsers))); if ($handles === []) { return []; } $written = $this->mentions->handlesAsWritten($body); return Profile::query() ->where('type', ProfileType::Organization) ->whereIn(DB::raw('LOWER(handle)'), $handles) ->orderBy('handle') ->get(['id', 'handle']) ->sortByDesc(fn (Profile $organization): bool => in_array($organization->handle, $written, true)) ->unique(fn (Profile $organization): string => Str::lower($organization->handle)) ->mapWithKeys(fn (Profile $organization): array => [Str::lower($organization->handle) => $organization->id]) ->all(); } }