Completed
Push — dev ( a106a3...7529c4 )
by Zach
03:50
created

ResourceRequest::messages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Larafolio\Http\Requests;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
abstract class ResourceRequest extends FormRequest
9
{
10
    /**
11
     * Type of resource.
12
     *
13
     * @var string
14
     */
15
    protected $resourceType = 'resource';
16
17
    /**
18
     * Determine if the user is authorized to make this request.
19
     *
20
     * @return bool
21
     */
22
    public function authorize()
23
    {
24
        return true;
25
    }
26
27
    /**
28
     * Get the validation rules that apply to the request.
29
     *
30
     * @return array
31
     */
32
    protected function processRules(Request $request, $nameRule)
33
    {
34
        $id = $request->input('id');
35
36
        if ($id) {
37
            $nameRule .= ','.$id;
38
        }
39
40
        return [
41
            'name'          => $nameRule,
42
            'blocks.*.text' => 'required',
43
        ];
44
    }
45
46
    /**
47
     * Error messages for validation rules.
48
     *
49
     * @return array
50
     */
51
    public function messages()
52
    {
53
        $type = ucfirst($this->resourceType);
54
55
        return [
56
            'name.required_with'     => $type.' name is required.',
57
            'name.unique'            => $type.' name is already taken.',
58
            'blocks.*.text.required' => 'All blocks must have text.'
59
        ];
60
    }
61
}
62