public function getCurrentMessages() { // Get the locations without duplicates $locations = Location::query()->where('user_id', '=', $this->id)->groupBy('message_id')->get(); // Check foreach message if it's the owner $new_locations = $locations->filter(function ($location) { if ($location->message->owner()->id == $this->id) { return true; } }); $messages = $new_locations->lists('message'); return $messages; }