feat: log in Hunts model

This commit is contained in:
Leon 2026-01-30 16:12:23 +01:00
parent 3b4c887d3d
commit c61b887ca8
1 changed files with 36 additions and 2 deletions

View File

@ -106,10 +106,37 @@ class Hunts extends Model
*/ */
public function toSearchableArray(): array 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; $status = $this->status instanceof HuntStatus ? $this->status->value : $this->status;
$difficulty = $this->difficulty instanceof HuntDifficulty ? $this->difficulty->value : $this->difficulty; $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, 'id' => $this->id,
'title' => $this->title, 'title' => $this->title,
'slug' => $this->slug, 'slug' => $this->slug,
@ -128,7 +155,14 @@ class Hunts extends Model
'end_at_timestamp' => $this->end_at?->timestamp, 'end_at_timestamp' => $this->end_at?->timestamp,
'created_at_timestamp' => $this->created_at->timestamp, 'created_at_timestamp' => $this->created_at->timestamp,
// IDs des participants pour le filtre de participation // 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;
} }
} }