1 | <?php |
||
15 | trait ErrorTrait |
||
16 | { |
||
17 | /** |
||
18 | * @var array The errors (key => value[]) |
||
19 | */ |
||
20 | protected $errors; |
||
21 | |||
22 | /** |
||
23 | * Identify whether there are any errors |
||
24 | * |
||
25 | * @param null $attribute |
||
26 | * @return bool |
||
27 | */ |
||
28 | public function hasErrors($attribute = null): bool |
||
33 | |||
34 | /** |
||
35 | * Returns the errors for all attribute or a single attribute. |
||
36 | * |
||
37 | * @param null $attribute |
||
38 | * @return array |
||
39 | */ |
||
40 | public function getErrors($attribute = null): array |
||
48 | |||
49 | /** |
||
50 | * Returns the first error of every attribute in the model. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | public function getFirstErrors(): array |
||
70 | |||
71 | /** |
||
72 | * Returns the first error of the specified attribute. |
||
73 | * |
||
74 | * @param $attribute |
||
75 | * @return string|null |
||
76 | */ |
||
77 | public function getFirstError($attribute) |
||
82 | |||
83 | /** |
||
84 | * Adds a new error to the specified attribute. |
||
85 | * |
||
86 | * @param $attribute |
||
87 | * @param string $error |
||
88 | */ |
||
89 | public function addError($attribute, $error = '') |
||
93 | |||
94 | /** |
||
95 | * Adds a list of errors. |
||
96 | * |
||
97 | * @param array $items |
||
98 | */ |
||
99 | public function addErrors(array $items) |
||
111 | |||
112 | /** |
||
113 | * Removes errors for all attributes or a single attribute. |
||
114 | * |
||
115 | * @param null $attribute |
||
116 | */ |
||
117 | public function clearErrors($attribute = null) |
||
125 | } |
||
126 |