ClientRequest::prepareForValidation()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Support\Str;
7
8
class ClientRequest extends FormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     */
13
    public function authorize(): bool
14
    {
15
        return true;
16
    }
17
18
    /**
19
     * Prepare the data for validation.
20
     */
21
    protected function prepareForValidation(): void
22
    {
23
        $this->merge([
24
            'slug' => ! is_null($this->name) ? Str::slug($this->name) : null,
25
        ]);
26
    }
27
28
    /**
29
     * Get the validation rules that apply to the request.
30
     *
31
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
32
     */
33
    public function rules(): array
34
    {
35
        $id = $this->client->id ?? '';
36
37
        return [
38
            'name' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_clients,name,'.$id,
39
            'slug' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_clients,slug,'.$id,
40
            'description' => 'nullable|max:5500',
41
            'group' => 'nullable|numeric',
42
            'position' => 'nullable|numeric',
43
            'featured' => 'nullable|boolean',
44
        ];
45
    }
46
}
47