58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\LogAction;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @mixin IdeHelperRequestedQuote
|
|
*/
|
|
class RequestedQuote extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'quote',
|
|
];
|
|
|
|
public function logs(): MorphOne
|
|
{
|
|
return $this->morphOne(Log::class, 'loggable');
|
|
}
|
|
|
|
public function approve(): void
|
|
{
|
|
Log::create([
|
|
'user_id' => auth()?->user()?->id,
|
|
'loggable_type' => self::class,
|
|
'loggable_id' => $this->id,
|
|
'action' => LogAction::APPROVE,
|
|
'content' => $this->quote,
|
|
'ip' => request()->ip(),
|
|
]);
|
|
|
|
Quote::create([
|
|
'quote' => $this->quote,
|
|
]);
|
|
|
|
$this->delete();
|
|
}
|
|
|
|
public function reject(): void
|
|
{
|
|
Log::create([
|
|
'user_id' => auth()?->user()?->id,
|
|
'loggable_type' => self::class,
|
|
'loggable_id' => $this->id,
|
|
'action' => LogAction::REJECT,
|
|
'content' => $this->quote,
|
|
'ip' => request()->ip(),
|
|
]);
|
|
|
|
$this->delete();
|
|
}
|
|
}
|