Passed
Push — main ( 6877e3...35b0cf )
by PRATIK
04:14
created

TestimonialRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 15
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
7
class TestimonialRequest 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->testimonial->code ?? rand(100000, 9999999)
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->testimonial->id ?? '';
40
        return [
41
            'code' => 'required|unique:testimonials,code,' . $id,
42
            'name' => 'required|max:255',
43
            'email' => 'required|unique:testimonials,email,' . $id,
44
            'image' => 'nullable|file|image|max:3000',
45
            'contact' => 'nullable|numeric',
46
            'designation' => 'nullable|max:60',
47
            'company' => 'nullable|max:60',
48
            'body' => 'required|max:3000',
49
            'rating' => 'nullable|numeric|max:5',
50
            'position' => 'sometimes|numeric',
51
            'approve' => 'sometimes|boolean'
52
        ];
53
    }
54
}
55