Reverse query to get participations with the current code

This commit is contained in:
Noah Lancien 2024-01-05 12:29:13 +01:00
parent 4739b48a28
commit 532f294a77

View file

@ -161,10 +161,11 @@ class Code extends Model
$settings = app(Settings::class);
return Attribute::make(
get: fn (): bool => $settings->nb_unique_code_use ?
Participation::where(
'code_unique_id',
$this->id
)->count() >= $settings->nb_unique_code_use : false
Code::query()->where('id', $this->id)->whereHas(
'participations',
operator: '>=',
count: $settings->nb_unique_code_use
)->count() : false
);
}
}