diff --git a/app/Models/Hunts.php b/app/Models/Hunts.php index 1d3249e..7301cf0 100644 --- a/app/Models/Hunts.php +++ b/app/Models/Hunts.php @@ -106,10 +106,37 @@ class Hunts extends Model */ public function toSearchableArray(): array { + \Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_START', [ + 'hunt_id' => $this->id, + 'hunt_title' => $this->title, + ]); + $status = $this->status instanceof HuntStatus ? $this->status->value : $this->status; $difficulty = $this->difficulty instanceof HuntDifficulty ? $this->difficulty->value : $this->difficulty; - return [ + \Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_ENUMS_CONVERTED', [ + 'hunt_id' => $this->id, + 'status' => $status, + 'difficulty' => $difficulty, + ]); + + try { + $participantIds = $this->participants()->pluck('user_id')->toArray(); + \Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_PARTICIPANTS_LOADED', [ + 'hunt_id' => $this->id, + 'participant_count' => count($participantIds), + 'participant_ids' => $participantIds, + ]); + } catch (\Throwable $e) { + \Illuminate\Support\Facades\Log::error('TO_SEARCHABLE_ARRAY_PARTICIPANTS_ERROR', [ + 'hunt_id' => $this->id, + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ]); + $participantIds = []; + } + + $searchableArray = [ 'id' => $this->id, 'title' => $this->title, 'slug' => $this->slug, @@ -128,7 +155,14 @@ class Hunts extends Model 'end_at_timestamp' => $this->end_at?->timestamp, 'created_at_timestamp' => $this->created_at->timestamp, // IDs des participants pour le filtre de participation - 'participant_ids' => $this->participants()->pluck('user_id')->toArray(), + 'participant_ids' => $participantIds, ]; + + \Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_COMPLETE', [ + 'hunt_id' => $this->id, + 'array_keys' => array_keys($searchableArray), + ]); + + return $searchableArray; } }