Completed
Push — dev ( 5d63f9...a106a3 )
by Zach
04:08
created

PageRequest::messages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 8
loc 8
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 View Code Duplication
class PageRequest extends FormRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules(Request $request)
26
    {
27
        $id = $request->input('id');
28
29
        $nameRule = 'required_with:type,links,lines,blocks|unique:pages,name';
30
31
        if ($id) {
32
            $nameRule .= ','.$id;
33
        }
34
35
        return [
36
            'name'          => $nameRule,
37
            'blocks.*.text' => 'required',
38
        ];
39
    }
40
41
    /**
42
     * Error messages for validation rules.
43
     *
44
     * @return array
45
     */
46
    public function messages()
47
    {
48
        return [
49
            'name.required_with'     => 'Page name is required.',
50
            'name.unique'            => 'Page name is already taken.',
51
            'blocks.*.text.required' => 'All blocks must have text.'
52
        ];
53
    }
54
}
55