ContactRequest::messages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace App\Http\Requests;
4
5
use App\Traits\CaptchaTrait;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class ContactRequest extends FormRequest
9
{
10
    use CaptchaTrait;
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
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
26
     */
27
    public function rules()
28
    {
29
        $captchaRequiredPlug = '';
30
31
        if (config('blog.services.reCaptchStatus')) {
32
            $captchaRequiredPlug = 'required';  // Rule
33
            $this->captchaCheck();              // Check
34
        }
35
36
        return [
37
            'firstname'             => 'required|max:255|string',
38
            'lastname'              => 'max:255|string',
39
            'email'                 => 'required|max:255|email',
40
            'phone'                 => 'numeric|nullable',
41
            'message'               => 'required|max:500|string',
42
            'g-recaptcha-response'  => $captchaRequiredPlug,
43
        ];
44
    }
45
46
    /**
47
     * Get the error messages for the defined validation rules.
48
     *
49
     * @return array
50
     */
51
    public function messages()
52
    {
53
        return [
54
            'g-recaptcha-response.required' => trans('forms.contact.validation.captcha'),
55
        ];
56
    }
57
}
58