feat: logging

This commit is contained in:
llama committed 2023-10-10 20:47:51 +11:00
1 parent b3784b77b1
commit ceb4f36ba1
12 files changed
+169 -24

No files matched your search

+27
View File
@@ -14,6 +14,16 @@ class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The model's default values for attributes.
*
* @var array
*/
protected $attributes = [
'is_admin' => false,
'status' => true,
];
/**
* The attributes that are mass assignable.
*
@@ -46,6 +56,23 @@ class User extends Authenticatable
* @var array<string, string>
*/
protected $casts = [
'is_admin' => 'boolean',
'status' => 'boolean',
'password' => 'hashed',
];
public static function boot(): void
{
parent::boot();
// These will only ever get created by the api/bot.
// If we want to add something like by whom later on,
// we can just append it to the content e.g auth()?->user()?->id ?? 'API'.
self::created(function ($model) {
Log::create([
'user_id' => $model->id,
'content' => 'User created.'
]);
});
}
}