| 1 | <?php |
||
| 14 | trait ElasticEloquent |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Model Boot method |
||
| 18 | */ |
||
| 19 | public static function bootElasticEloquent() |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Returns the type used to index models on Elastic Search |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | public function getIndexType() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Returns the id used to index models on Elastic Search |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | public function getIndexId() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns the different parameters to be indexed |
||
| 44 | * @return mixed |
||
| 45 | */ |
||
| 46 | public function getSearchableIndex() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Reindexes the model |
||
| 53 | */ |
||
| 54 | public function reindex() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns the DB name |
||
| 68 | * @return mixed |
||
| 69 | */ |
||
| 70 | public abstract function getTable(); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Returns the model primary key |
||
| 74 | * @return mixed |
||
| 75 | */ |
||
| 76 | public abstract function getKey(); |
||
| 77 | } |
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
Idableprovides a methodequalsIdthat 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.