1 | <?php |
||
21 | class Guardian extends Model implements AuthenticatableContract, AuthorizableContract |
||
22 | { |
||
23 | // @TODO: Strangely, this issue happens only here!!! |
||
|
|||
24 | // Duplicate trait usage to fire attached events for cache |
||
25 | // flush before other events in other traits specially LogsActivity, |
||
26 | // otherwise old cached queries used and no changelog recorded on update. |
||
27 | use CacheableEloquent; |
||
28 | use Auditable; |
||
29 | use LogsActivity; |
||
30 | use Authorizable; |
||
31 | use HasHashables; |
||
32 | use Authenticatable; |
||
33 | use ValidatingTrait; |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | protected $fillable = [ |
||
39 | 'username', |
||
40 | 'password', |
||
41 | 'email', |
||
42 | 'is_active', |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | protected $casts = [ |
||
49 | 'username' => 'string', |
||
50 | 'password' => 'string', |
||
51 | 'email' => 'string', |
||
52 | 'is_active' => 'boolean', |
||
53 | 'deleted_at' => 'datetime', |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | protected $hidden = [ |
||
60 | 'password', |
||
61 | 'remember_token', |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | protected $observables = [ |
||
68 | 'validating', |
||
69 | 'validated', |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * The attributes to be encrypted before saving. |
||
74 | * |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $hashables = [ |
||
78 | 'password', |
||
79 | ]; |
||
80 | |||
81 | /** |
||
82 | * The default rules that the model will validate against. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $rules = []; |
||
87 | |||
88 | /** |
||
89 | * Whether the model should throw a |
||
90 | * ValidationException if it fails validation. |
||
91 | * |
||
92 | * @var bool |
||
93 | */ |
||
94 | protected $throwValidationExceptions = true; |
||
95 | |||
96 | /** |
||
97 | * Indicates whether to log only dirty attributes or all. |
||
98 | * |
||
99 | * @var bool |
||
100 | */ |
||
101 | protected static $logOnlyDirty = true; |
||
102 | |||
103 | /** |
||
104 | * The attributes that are logged on change. |
||
105 | * |
||
106 | * @var array |
||
107 | */ |
||
108 | protected static $logFillable = true; |
||
109 | |||
110 | /** |
||
111 | * The attributes that are ignored on change. |
||
112 | * |
||
113 | * @var array |
||
114 | */ |
||
115 | protected static $ignoreChangedAttributes = [ |
||
116 | 'password', |
||
117 | 'created_at', |
||
118 | 'updated_at', |
||
119 | 'deleted_at', |
||
120 | ]; |
||
121 | |||
122 | /** |
||
123 | * Create a new Eloquent model instance. |
||
124 | * |
||
125 | * @param array $attributes |
||
126 | */ |
||
127 | public function __construct(array $attributes = []) |
||
140 | |||
141 | /** |
||
142 | * Get the value of the model's route key. |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function getRouteKey() |
||
150 | |||
151 | /** |
||
152 | * Retrieve the model for a bound value. |
||
153 | * |
||
154 | * @param mixed $value |
||
155 | * @return \Illuminate\Database\Eloquent\Model|null |
||
156 | */ |
||
157 | public function resolveRouteBinding($value) |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | protected static function boot() |
||
179 | |||
180 | /** |
||
181 | * The user may have many sessions. |
||
182 | * |
||
183 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
184 | */ |
||
185 | public function sessions(): MorphMany |
||
189 | |||
190 | /** |
||
191 | * Activate the user. |
||
192 | * |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function activate() |
||
201 | |||
202 | /** |
||
203 | * Deactivate the user. |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function deactivate() |
||
213 | } |
||
214 |