-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRedeRequest.php
More file actions
64 lines (60 loc) · 2.19 KB
/
RedeRequest.php
File metadata and controls
64 lines (60 loc) · 2.19 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Rules\MultiplesIP;
use App\Rules\Domain;
use App\Rules\PertenceRede;
use App\Utils\Freeradius;
use App\Rules\RedeCidr;
class RedeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'nome' => ['required'],
'shared_network' => 'required',
'iprede' => ['ip','required','different:gateway'],
'cidr' => 'required|integer|min:8|max:30',
'vlan' => 'integer',
'gateway' => ['ip','required', new PertenceRede($this->iprede, $this->cidr)],
'dns' => [new MultiplesIP('DNS')],
'netbios' => [new MultiplesIP('NetBIOS')],
'ad_domain' => [new Domain('Active Directory Domain')],
'ntp' => [new MultiplesIP('NTP')],
'active_dhcp' => 'nullable|boolean',
'active_freeradius' => 'nullable|boolean',
'onlyadmin' => 'nullable|boolean',
'dhcpd_subnet_options' => 'nullable',
];
if ($this->method() == 'PATCH' || $this->method() == 'PUT'){
array_push($rules['nome'], 'unique:redes,nome,' .$this->rede->id);
array_push($rules['iprede'], new RedeCidr($this->cidr,$this->iprede,$this->rede->id));
} else {
array_push($rules['nome'], 'unique:redes');
array_push($rules['iprede'], new RedeCidr($this->cidr,$this->iprede));
}
return $rules;
}
protected function prepareForValidation()
{
$this->merge([
'active_dhcp' => isset($this->active_dhcp) ? $this->active_dhcp:0,
'active_freeradius' => isset($this->active_freeradius) ? $this->active_freeradius:0,
'onlyadmin' => isset($this->onlyadmin) ? $this->onlyadmin:0,
]);
}
}