Passed
Push — main ( 86a6dd...ec1f24 )
by PRATIK
03:12
created

EventRequest::prepareForValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Adminetic\Website\Http\Requests;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class EventRequest extends FormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        return true;
18
    }
19
20
21
    /**
22
     * Prepare the data for validation.
23
     *
24
     * @return void
25
     */
26
    protected function prepareForValidation()
27
    {
28
        $this->merge([
29
            'code' => $this->event->code ?? rand(100000, 999999),
30
            'slug' => Str::slug($this->name)
31
        ]);
32
    }
33
34
    /**
35
     * Get the validation rules that apply to the request.
36
     *
37
     * @return array
38
     */
39
    public function rules()
40
    {
41
        $id = $this->event->id ?? '';
42
        return [
43
            'slug' => 'required|max:255|unique:events,slug,' . $id,
44
            'code' => 'required|max:255|unique:events,code,' . $id,
45
            'name' => 'required|max:255',
46
            'description' => 'required|max:55000',
47
            'single_day' => 'sometimes|boolean',
48
            'event_date' => 'required_if:single_day,1',
49
            'start_date' => 'required_if:single_day,0',
50
            'end_date' => 'required_if:single_day,0',
51
            'interval' => 'required_if:single_day,0',
52
            'notice' => 'nullable|max:255',
53
            'image' => 'nullable|file|image|max:3000',
54
            'gallery_id' => 'nullable|numeric',
55
            'meta_name' => 'nullable|max:255',
56
            'meta_description' => 'nullable|max:255',
57
            'meta_keywords' => 'nullable',
58
        ];
59
    }
60
}
61