| 1 | <?php |
||
| 8 | trait AutoCache |
||
| 9 | {
|
||
| 10 | /** |
||
| 11 | * Set the cache expiry time. |
||
| 12 | * |
||
| 13 | * @var int |
||
| 14 | */ |
||
| 15 | public $cacheExpiry = 1440; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The "booting" method of the model. |
||
| 19 | * |
||
| 20 | * @return void |
||
| 21 | */ |
||
| 22 | 6 | public static function boot() |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Create a new Eloquent query builder for the model. |
||
| 35 | * |
||
| 36 | * @param \Illuminate\Database\Query\Builder $query |
||
| 37 | * @return \PulkitJalan\Cacheable\Eloquent\Builder|static |
||
| 38 | */ |
||
| 39 | public function newEloquentBuilder($query) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Refresh the current models cache. |
||
| 46 | * |
||
| 47 | * @return $this |
||
| 48 | */ |
||
| 49 | public function refresh() |
||
| 55 | } |
||
| 56 |
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.