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

TestimonialRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

3 Methods

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