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