1 | <?php namespace Arcanedev\LaravelAuth\Models\Traits; |
||
14 | trait Activatable |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Getters & Setters |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * Get the `is_active` attribute. |
||
23 | * |
||
24 | * @return bool |
||
25 | */ |
||
26 | 15 | public function getIsActiveAttribute() |
|
30 | |||
31 | /* ----------------------------------------------------------------- |
||
32 | | Main Methods |
||
33 | | ----------------------------------------------------------------- |
||
34 | */ |
||
35 | |||
36 | /** |
||
37 | * Activate/deactivate the model. |
||
38 | * |
||
39 | * @param bool $active |
||
40 | * @param bool $save |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | 9 | protected function switchActive($active, $save = true) |
|
50 | |||
51 | /* ----------------------------------------------------------------- |
||
52 | | Check Methods |
||
53 | | ----------------------------------------------------------------- |
||
54 | */ |
||
55 | |||
56 | /** |
||
57 | * Check if the model is active. |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 75 | public function isActive() |
|
65 | } |
||
66 |
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.