Completed
Push — main ( 7e4d39...6c6f0a )
by PRATIK
18s queued 15s
created

PopupRequest::prepareForValidation()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
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
9
class PopupRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     */
14
    public function authorize(): bool
15
    {
16
        return true;
17
    }
18
19
    protected function prepareForValidation(): void
20
    {
21
        $this->merge([
22
            'slug' => ! is_null($this->name) ? Str::slug($this->name) : null,
23
            'meta_name' => $this->popup->meta_name ?? $this->meta_name ?? $this->name ?? null,
24
            'meta_description' => $this->popup->meta_description ?? $this->meta_description ?? $this->excerpt ?? 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->popup->id ?? '';
36
        return [
37
            'slug' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,slug,'.$id,
38
            'name' => 'required|max:100|unique:'.config('website.table_prefix', 'website').'_categories,name,'.$id,
39
            'excerpt' => 'nullable|max:5500',
40
            'description' => 'nullable|max:55000',
41
            'category_id' => 'nullable|exists:'.config('website.table_prefix', 'website').'_categories,id',
42
            'active' => 'sometimes|boolean',
43
            'position' => 'nullable|numeric',
44
            'icon' => 'nullable|max:255',
45
            'color' => 'nullable|max:255',
46
            'expire' => 'nullable|max:255',
47
            'data' => 'nullable',
48
            'meta_name' => 'nullable|max:100',
49
            'meta_description' => 'nullable|max:255',
50
            'meta_keywords' => 'nullable|max:100',
51
            'videos' => 'nullable',
52
            'popup' => 'sometimes|numeric',
53
        ];
54
    }
55
}
56