1 | <?php |
||
8 | abstract class Request extends FormRequest |
||
9 | { |
||
10 | /** |
||
11 | * Validation rules that apply to the request. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | public $rules = []; |
||
16 | |||
17 | /** |
||
18 | * Human friendly names of the request fields under validation. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $labels = []; |
||
23 | |||
24 | /** |
||
25 | * Class constructor. |
||
26 | * |
||
27 | * @param array |
||
28 | * @return void |
||
|
|||
29 | */ |
||
30 | public function __construct(array $rules = []) |
||
36 | |||
37 | /** |
||
38 | * Get the validation rules that apply to the request. |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | public function rules() |
||
57 | |||
58 | /** |
||
59 | * Get the human friendly names of the request fields under validation. |
||
60 | * |
||
61 | * @return object |
||
62 | */ |
||
63 | public function labels() |
||
67 | |||
68 | /** |
||
69 | * Set custom attributes for validator errors. |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public function attributes() |
||
77 | |||
78 | /** |
||
79 | * Determine if the user is authorized to make this request. |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function authorize() |
||
89 | |||
90 | /** |
||
91 | * Get the resource primary key (id) from request URL. |
||
92 | * |
||
93 | * NOTE: It can also be retrieved from the route parameter name using |
||
94 | * $this->route('paramName') method, but that involves knowing the name |
||
95 | * of the parameter beforehand. i.e: |
||
96 | * |
||
97 | * For the route |
||
98 | * Route::post('comment/{comment}') |
||
99 | * |
||
100 | * the value of $comment can be retrieved by |
||
101 | * |
||
102 | * $this->route('comment'); |
||
103 | * |
||
104 | * @return integer|null |
||
105 | */ |
||
106 | public function getKey() |
||
113 | |||
114 | /** |
||
115 | * Parse validation rules in compact format. |
||
116 | * |
||
117 | * Converts: |
||
118 | * |
||
119 | * [ |
||
120 | * 'field1' => ['Label1', 'A|B'], |
||
121 | * 'field2' => ['Label2', ['C','D']], |
||
122 | * ]; |
||
123 | * |
||
124 | * To: |
||
125 | * |
||
126 | * [ |
||
127 | * 'labels' => [ |
||
128 | * 'field1' => 'Label1', |
||
129 | * 'field2' => 'Label2', |
||
130 | * ], |
||
131 | * 'rules' => [ |
||
132 | * 'field1' => ['A', 'B'], |
||
133 | * 'field2' => ['C', 'D'], |
||
134 | * ] |
||
135 | * ]; |
||
136 | * |
||
137 | * @param array |
||
138 | * @return array |
||
139 | */ |
||
140 | public static function parseRulesAndLabels(array $originalRules) |
||
175 | } |
||
176 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.