Completed
Push — develop ( a6e08d...e14194 )
by Abdelrahman
01:30
created

TenantFormRequest::withValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\Http\Requests\Adminarea;
6
7
use Rinvex\Support\Traits\Escaper;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class TenantFormRequest extends FormRequest
11
{
12
    use Escaper;
13
14
    /**
15
     * Determine if the user is authorized to make this request.
16
     *
17
     * @return bool
18
     */
19
    public function authorize(): bool
20
    {
21
        return true;
22
    }
23
24
    /**
25
     * Configure the validator instance.
26
     *
27
     * @param \Illuminate\Validation\Validator $validator
28
     *
29
     * @return void
30
     */
31
    public function withValidator($validator): void
32
    {
33
        // Sanitize input data before submission
34
        $this->replace($this->escape($this->all()));
35
    }
36
37
    /**
38
     * Prepare the data for validation.
39
     *
40
     * @return void
41
     */
42
    protected function prepareForValidation(): void
43
    {
44
        $data = $this->all();
45
46
        $data['owner_type'] = 'manager';
47
48
        $this->replace($data);
49
    }
50
51
    /**
52
     * Get the validation rules that apply to the request.
53
     *
54
     * @return array
55
     */
56
    public function rules(): array
57
    {
58
        $tenant = $this->route('tenant') ?? app('rinvex.tenants.tenant');
59
        $tenant->updateRulesUniques();
60
61
        return $tenant->getRules();
62
    }
63
}
64