where('context', $context); } public function scopeForHero(Builder $query, ?string $heroType): Builder { if ($heroType) { return $query->where(function ($q) use ($heroType) { $q->where('hero_type', $heroType) ->orWhereNull('hero_type'); }); } return $query->whereNull('hero_type'); } public static function getRandomText(string $context, ?string $heroType = null): ?self { $query = static::forContext($context); if ($heroType) { // Priorité aux textes spécifiques au héros, sinon textes génériques $heroSpecific = (clone $query)->where('hero_type', $heroType)->inRandomOrder()->first(); if ($heroSpecific) { return $heroSpecific; } } return $query->whereNull('hero_type')->inRandomOrder()->first(); } }