Skip to content

Commit 7735446

Browse files
committed
Only show prepaid badges if creation is possible
1 parent 6fe90d3 commit 7735446

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

app/Http/Controllers/WelcomeController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Models\Badge\Badge;
65
use Illuminate\Support\Facades\Auth;
7-
use Illuminate\Support\Facades\Gate;
86
use Inertia\Inertia;
97

108
class WelcomeController extends Controller
@@ -16,7 +14,7 @@ public function __invoke()
1614
$event = \App\Models\Event::getActiveEvent();
1715

1816
$prepaidBadgesLeft = 0;
19-
if ($event && Auth::check() && Gate::allows('create', Badge::class)) {
17+
if ($event && Auth::check()) {
2018
$user = Auth::user();
2119
$prepaidBadgesLeft = $user->getPrepaidBadgesLeft($event->id);
2220
}

app/Models/User.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Illuminate\Database\Eloquent\Factories\HasFactory;
1515
use Illuminate\Foundation\Auth\User as Authenticatable;
1616
use Illuminate\Notifications\Notifiable;
17+
use Illuminate\Support\Facades\Gate;
1718

1819
class User extends Authenticatable implements Customer, FilamentUser, Wallet, WalletFloat
1920
{
@@ -104,6 +105,11 @@ public function getPrepaidBadgesLeft($eventId = null): int
104105
return 0;
105106
}
106107

108+
// Check if Badges can be created (e.g. order deadline is over)
109+
if (! Gate::allows('create', Badge::class)) {
110+
return 0;
111+
}
112+
107113
$prepaidBadges = $eventUser->prepaid_badges;
108114
$orderedBadges = $this->badges()
109115
->whereHas('fursuit.event', function ($query) use ($event) {

0 commit comments

Comments
 (0)