Archived
feat: basic log page
This commit is contained in:
1 parent
faaed8fa1b
commit
e3bb7cb69f
12 files changed
+131
-16
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @mixin IdeHelperLog
|
||||
@@ -15,4 +16,19 @@ class Log extends Model
|
||||
'requested_quote_id',
|
||||
'content',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function quote(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Quote::class);
|
||||
}
|
||||
|
||||
public function requestedQuote(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RequestedQuote::class);
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
@@ -20,13 +21,19 @@ class Quote extends Model
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $this->id,
|
||||
'content' => 'Quote requested.'
|
||||
'content' => 'Quote requested.',
|
||||
]);
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'quote',
|
||||
];
|
||||
|
||||
public function logs(): hasMany
|
||||
{
|
||||
return $this->hasMany(Log::class);
|
||||
}
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
@@ -35,7 +42,7 @@ class Quote extends Model
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $model->id,
|
||||
'content' => 'Quote created.'
|
||||
'content' => 'Quote created.',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -43,7 +50,7 @@ class Quote extends Model
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'quote_id' => $model->id,
|
||||
'content' => 'Quote deleted.'
|
||||
'content' => 'Quote deleted.',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
@@ -17,12 +18,17 @@ class RequestedQuote extends Model
|
||||
'user_id',
|
||||
];
|
||||
|
||||
public function logs(): hasMany
|
||||
{
|
||||
return $this->hasMany(Log::class);
|
||||
}
|
||||
|
||||
public function approve(): void
|
||||
{
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'requested_quote_id' => $this->id,
|
||||
'content' => 'Quote approved.'
|
||||
'content' => 'Quote approved.',
|
||||
]);
|
||||
|
||||
Quote::create([
|
||||
@@ -37,7 +43,7 @@ class RequestedQuote extends Model
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'requested_quote_id' => $this->id,
|
||||
'content' => 'Quote rejected.'
|
||||
'content' => 'Quote rejected.',
|
||||
]);
|
||||
|
||||
$this->delete();
|
||||
|
||||
+12
-1
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -61,6 +62,16 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
public function logs(): hasMany
|
||||
{
|
||||
return $this->hasMany(Log::class);
|
||||
}
|
||||
|
||||
public function fullName(): string
|
||||
{
|
||||
return "{$this->firstname} {$this->lastname}";
|
||||
}
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
@@ -71,7 +82,7 @@ class User extends Authenticatable
|
||||
self::created(function ($model) {
|
||||
Log::create([
|
||||
'user_id' => $model->id,
|
||||
'content' => 'User created.'
|
||||
'content' => 'User created.',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user