1 | <?php |
||
8 | trait AutoValidate |
||
9 | { |
||
10 | /** |
||
11 | * An array of validation rules |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $rules = []; |
||
15 | |||
16 | /** |
||
17 | * An array of validation messages |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $messages = []; |
||
21 | |||
22 | /** |
||
23 | * A method best used to register Eloquent events when the model boots up |
||
24 | * @return void |
||
25 | */ |
||
26 | protected static function boot() |
||
34 | |||
35 | /** |
||
36 | * Validates the Model |
||
37 | * @return boolean Whether or not the input is valid |
||
38 | */ |
||
39 | public function validate() |
||
53 | |||
54 | /** |
||
55 | * Returns an array of validation rules |
||
56 | * @return array An Array of validation rules |
||
57 | */ |
||
58 | protected function getValidationRules() |
||
62 | |||
63 | /** |
||
64 | * Returns an array of validation messages |
||
65 | * @return array An Array of validation messages |
||
66 | */ |
||
67 | protected function getValidationMessages() |
||
71 | } |
||
72 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.