-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbacCheckRequest.php
More file actions
39 lines (34 loc) · 1.35 KB
/
AbacCheckRequest.php
File metadata and controls
39 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace zennit\ABAC\Http\Requests;
use Illuminate\Validation\Rule;
use zennit\ABAC\Enums\Operators\AllOperators;
use zennit\ABAC\Enums\Operators\LogicalOperators;
use zennit\ABAC\Models\AbacChain;
class AbacCheckRequest extends Request
{
protected function getRules(): array
{
return [
'chains.*.checks' => [
'required',
'array',
'max:2',
function ($attribute, $value, $fail) {
$chainIndex = explode('.', $attribute)[1];
$chain = $this->input("chains.$chainIndex");
$totalChildren = count($value);
if (isset($chain['chains'])) {
$totalChildren += count($chain['chains']);
}
if ($totalChildren > 2) {
$fail('Total number of children (chains + checks) cannot exceed 2');
}
},
],
'chains.*.checks.*.chain_id' => ['required', 'integer', 'exists:' . AbacChain::class . ',id'],
'chains.*.checks.*.operator' => ['required', 'string', Rule::in(AllOperators::values(LogicalOperators::cases()))],
'chains.*.checks.*.key' => ['required', 'string'],
'chains.*.checks.*.value' => ['required', 'string'],
];
}
}