Passed
Push — main ( 21b81c...b80092 )
by PRATIK
14:07
created

PopupRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
7
class PopupRequest extends FormRequest
8
{
9
    /**
10
     * Determine if the user is authorized to make this request.
11
     *
12
     * @return bool
13
     */
14
    public function authorize()
15
    {
16
        return true;
17
    }
18
19
20
    /**
21
     * Prepare the data for validation.
22
     *
23
     * @return void
24
     */
25
    protected function prepareForValidation()
26
    {
27
        $this->merge([
28
            'code' => $this->popup->code ?? rand(100000, 9999998)
29
        ]);
30
    }
31
32
    /**
33
     * Get the validation rules that apply to the request.
34
     *
35
     * @return array
36
     */
37
    public function rules()
38
    {
39
        $id = $this->popup->id ?? '';
40
        return [
41
            'code' => 'required|unique:popups,code,' . $id,
42
            'name' => 'nullable|max:255',
43
            'image' => 'nullable|file|image|max:3000',
44
            'body' => 'nullable|max:5500',
45
            'url' => 'nullable|max:255',
46
            'position' => 'sometimes|numeric'
47
        ];
48
    }
49
}
50