FeatureRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareForValidation() 0 6 2
A authorize() 0 3 1
A rules() 0 18 1
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