58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @mixin IdeHelperQuote
|
|
*/
|
|
class Quote extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
public function request(): void
|
|
{
|
|
// 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 function logs(): hasMany
|
|
{
|
|
return $this->hasMany(Log::class);
|
|
}
|
|
|
|
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.',
|
|
]);
|
|
});
|
|
}
|
|
}
|