optimizations

This commit is contained in:
2026-03-28 19:15:39 +01:00
parent 0b25d9570a
commit cab4fbd83e
509 changed files with 1016804 additions and 1605 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Services\NovaCards;
use App\Models\NovaCard;
use App\Models\NovaCardChallenge;
use App\Models\NovaCardChallengeEntry;
use App\Models\User;
class NovaCardChallengeService
{
public function submit(User $user, NovaCardChallenge $challenge, NovaCard $card, ?string $note = null): NovaCardChallengeEntry
{
$entry = NovaCardChallengeEntry::query()->updateOrCreate([
'challenge_id' => $challenge->id,
'card_id' => $card->id,
], [
'user_id' => $user->id,
'status' => NovaCardChallengeEntry::STATUS_ACTIVE,
'note' => $note,
]);
$challenge->forceFill([
'entries_count' => NovaCardChallengeEntry::query()->where('challenge_id', $challenge->id)->count(),
])->save();
$card->forceFill([
'challenge_entries_count' => NovaCardChallengeEntry::query()->where('card_id', $card->id)->count(),
'last_engaged_at' => now(),
])->save();
return $entry;
}
}