Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| StoreRolePlayProjectRequest | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
4.01 | |
0.00% |
0 / 1 |
| authorize | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
3.01 | |||
| rules | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\v2\RolePlay; |
| 4 | |
| 5 | use App\Http\Models\RolePlayProjects; |
| 6 | use App\Http\Models\UserAddOns; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | |
| 9 | class StoreRolePlayProjectRequest extends FormRequest |
| 10 | { |
| 11 | /** |
| 12 | * Determine if the user is authorized to make this request. |
| 13 | * |
| 14 | * @return bool |
| 15 | */ |
| 16 | public function authorize(): bool |
| 17 | { |
| 18 | $user = $this->user(); |
| 19 | |
| 20 | $rolePlayAddOn = UserAddOns::where('user_id', $user->id) |
| 21 | ->where('product', 'RolePlay') |
| 22 | ->where('status', 'active') |
| 23 | ->orderBy('created_at', 'desc') |
| 24 | ->first(); |
| 25 | |
| 26 | if (!$rolePlayAddOn) { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | $rolePlayAddOn->load('addOn'); |
| 31 | |
| 32 | $project_credits = $rolePlayAddOn->addOn->features['project_credits'] ?? 1; |
| 33 | |
| 34 | $usedRolePlayProjects = RolePlayProjects::where('user_id', $user->id)->count() ?? 0; |
| 35 | |
| 36 | return $project_credits === -1 || $usedRolePlayProjects < $project_credits; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the validation rules that apply to the request. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public function rules(): array |
| 45 | { |
| 46 | return RolePlayProjects::getRules(); |
| 47 | } |
| 48 | } |