ContactFormRequest::prepareForValidation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
cc 1
nc 1
nop 0
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\Http\Requests\Adminarea;
6
7
use Rinvex\Support\Traits\Escaper;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class ContactFormRequest 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
     * Prepare the data for validation.
26
     *
27
     * @return void
28
     */
29
    protected function prepareForValidation(): void
30
    {
31
        $data = $this->all();
32
33
        $data['entity_id'] = $this->user($this->route('guard'))->getKey();
34
        $data['entity_type'] = $this->user($this->route('guard'))->getMorphClass();
35
36
        $this->replace($data);
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
        $contact = $this->route('contact') ?? app('rinvex.contacts.contact');
47
        $contact->updateRulesUniques();
48
49
        return $contact->getRules();
50
    }
51
}
52