ldc-gen-game-web/app/Policies/InstantWinPolicy.php
2025-08-29 14:46:51 +02:00

38 lines
1,000 B
PHP

<?php
namespace App\Policies;
use App\Models\InstantWin;
use App\Models\Prize;
use App\Models\User;
use App\Policies\Rules\UserStaticRules;
class InstantWinPolicy
{
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function viewAny(User $authUser): bool
{
return UserStaticRules::restrictTenant($authUser);
}
/**
* Determine whether the user can generate models.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function generate(User $authUser): bool
{
$instantWinCount = InstantWin::query()->with('prize')->whereHas('prize', function ($query) {
$query->where('tenant_id', tenant('id'));
})->count();
$prizeCached = Prize::getCached()->count();
return UserStaticRules::restrictTenant($authUser) and
(($prizeCached and !$instantWinCount) ? true : false);
}
}