Passed
Push — main ( 52a9ba...b89683 )
by PRATIK
04:37 queued 14s
created

CategoryRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 17
rs 9.7666
c 1
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Adminetic\Website\Models\Admin\Category;
8
use Cviebrock\EloquentSluggable\Services\SlugService;
0 ignored issues
show
Bug introduced by
The type Cviebrock\EloquentSluggable\Services\SlugService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class CategoryRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize()
18
    {
19
        return true;
20
    }
21
22
    /**
23
     * Prepare the data for validation.
24
     *
25
     * @return void
26
     */
27
    protected function prepareForValidation()
28
    {
29
        if ($this->category_id) {
30
            $category = Category::find($this->category_id);
31
            $this->merge([
32
                'model' => $category->model ?? $this->model ?? null
33
            ]);
34
        }
35
        $this->merge([
36
            'code' => $this->category->code ?? rand(100000, 999999),
37
            'slug' => Str::slug($this->name)
38
        ]);
39
    }
40
41
    /**
42
     * Get the validation rules that apply to the request.
43
     *
44
     * @return array
45
     */
46
    public function rules()
47
    {
48
        $id = $this->category->id ?? '';
49
        return [
50
            'model' => 'required|max:255',
51
            'code' => 'required|unique:categories,code,' . $id,
52
            'name' => 'required|max:255',
53
            'slug' => 'required|unique:categories,slug,' . $id,
54
            'category_id' => 'nullable|numeric',
55
            'active' => 'sometimes|boolean',
56
            'color' => 'nullable|max:12',
57
            'icon' => 'nullable|max:20',
58
            'image' => 'nullable|file|image|max:3000',
59
            'description' => 'nullable|max:3000',
60
            'meta_name' => 'nullable|max:255',
61
            'meta_description' => 'nullable|max:255',
62
            'meta_name' => 'nullable',
63
        ];
64
    }
65
}
66