Archived
feat: logging
This commit is contained in:
1 parent
b3784b77b1
commit
ceb4f36ba1
12 files changed
+169
-24
No files matched your search
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperLog
|
||||
*/
|
||||
class Log extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'quote_id',
|
||||
'requested_quote_id',
|
||||
'content',
|
||||
];
|
||||
}
|
||||
+28
-2
@@ -14,11 +14,37 @@ class Quote extends Model
|
||||
|
||||
public function request(): void
|
||||
{
|
||||
// Send the notification
|
||||
// Send the quote
|
||||
// If success, add it to the transactions
|
||||
}
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $this->id,
|
||||
'content' => 'Quote requested.'
|
||||
]);
|
||||
}
|
||||
protected $fillable = [
|
||||
'quote',
|
||||
];
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::created(function ($model) {
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $model->id,
|
||||
'content' => 'Quote created.'
|
||||
]);
|
||||
});
|
||||
|
||||
self::deleted(function ($model) {
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $model->id,
|
||||
'content' => 'Quote deleted.'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,12 @@ class RequestedQuote extends Model
|
||||
|
||||
public function approve(): void
|
||||
{
|
||||
// TODO: we'll probs want to log who approved this quote
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'requested_quote_id' => $this->id,
|
||||
'content' => 'Quote approved.'
|
||||
]);
|
||||
|
||||
Quote::create([
|
||||
'quote' => $this->quote,
|
||||
]);
|
||||
@@ -29,7 +34,11 @@ class RequestedQuote extends Model
|
||||
|
||||
public function reject(): void
|
||||
{
|
||||
// TODO: we'll probs want to log who reject this quote
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'requested_quote_id' => $this->id,
|
||||
'content' => 'Quote rejected.'
|
||||
]);
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
@@ -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.'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user