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 HashidsTrait; |
||
30 | use LogsActivity; |
||
31 | use Authorizable; |
||
32 | use HasHashables; |
||
33 | use Authenticatable; |
||
34 | use ValidatingTrait; |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | protected $fillable = [ |
||
40 | 'username', |
||
41 | 'password', |
||
42 | 'email', |
||
43 | 'is_active', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | protected $casts = [ |
||
50 | 'username' => 'string', |
||
51 | 'password' => 'string', |
||
52 | 'email' => 'string', |
||
53 | 'is_active' => 'boolean', |
||
54 | 'deleted_at' => 'datetime', |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | protected $hidden = [ |
||
61 | 'password', |
||
62 | 'remember_token', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | protected $observables = [ |
||
69 | 'validating', |
||
70 | 'validated', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * The attributes to be encrypted before saving. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $hashables = [ |
||
79 | 'password', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * The default rules that the model will validate against. |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $rules = []; |
||
88 | |||
89 | /** |
||
90 | * Whether the model should throw a |
||
91 | * ValidationException if it fails validation. |
||
92 | * |
||
93 | * @var bool |
||
94 | */ |
||
95 | protected $throwValidationExceptions = true; |
||
96 | |||
97 | /** |
||
98 | * Indicates whether to log only dirty attributes or all. |
||
99 | * |
||
100 | * @var bool |
||
101 | */ |
||
102 | protected static $logOnlyDirty = true; |
||
103 | |||
104 | /** |
||
105 | * The attributes that are logged on change. |
||
106 | * |
||
107 | * @var array |
||
108 | */ |
||
109 | protected static $logFillable = true; |
||
110 | |||
111 | /** |
||
112 | * The attributes that are ignored on change. |
||
113 | * |
||
114 | * @var array |
||
115 | */ |
||
116 | protected static $ignoreChangedAttributes = [ |
||
117 | 'password', |
||
118 | 'created_at', |
||
119 | 'updated_at', |
||
120 | 'deleted_at', |
||
121 | ]; |
||
122 | |||
123 | /** |
||
124 | * Create a new Eloquent model instance. |
||
125 | * |
||
126 | * @param array $attributes |
||
127 | */ |
||
128 | public function __construct(array $attributes = []) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | protected static function boot() |
||
157 | |||
158 | /** |
||
159 | * The user may have many sessions. |
||
160 | * |
||
161 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
162 | */ |
||
163 | public function sessions(): MorphMany |
||
167 | |||
168 | /** |
||
169 | * Activate the user. |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function activate() |
||
174 | { |
||
175 | $this->update(['is_active' => true]); |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Deactivate the user. |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function deactivate() |
||
186 | { |
||
187 | $this->update(['is_active' => false]); |
||
188 | |||
189 | return $this; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Get the route key for the model. |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getRouteKeyName() |
||
201 | } |
||
202 |