FeatureRequest::prepareForValidation()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
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 FeatureRequest 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
            'meta_name' => $this->feature->meta_name ?? $this->meta_name ?? $this->name ?? null,
26
            'meta_description' => $this->feature->meta_description ?? $this->meta_description ?? $this->excerpt ?? null,
27
        ]);
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
34
     */
35
    public function rules(): array
36
    {
37
        $id = $this->feature->id ?? '';
38
39
        return [
40
            'slug' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,slug,'.$id,
41
            'name' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,name,'.$id,
42
            'excerpt' => 'nullable|max:5500',
43
            'description' => 'nullable|max:55000',
44
            'category_id' => 'nullable|exists:'.config('website.table_prefix', 'website').'_categories,id',
45
            'active' => 'sometimes|boolean',
46
            'featured' => 'sometimes|boolean',
47
            'position' => 'nullable|numeric',
48
            'icon' => 'nullable|max:255',
49
            'color' => 'nullable|max:255',
50
            'meta_name' => 'nullable|max:100',
51
            'meta_description' => 'nullable|max:255',
52
            'meta_keywords' => 'nullable|max:100',
53
        ];
54
    }
55
}
56