2023-12-05 12:33:25 +01:00
|
|
|
<?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
|
|
|
|
|
{
|
2025-04-18 16:59:57 +02:00
|
|
|
return UserStaticRules::restrictTenant($authUser);
|
2023-12-05 12:33:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can generate models.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\User $authUser
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function generate(User $authUser): bool
|
|
|
|
|
{
|
2025-04-18 16:59:57 +02:00
|
|
|
$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);
|
2023-12-05 12:33:25 +01:00
|
|
|
}
|
|
|
|
|
}
|