52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\MutationFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
|
|
|
class Mutation extends Model
|
|
{
|
|
/** @use HasFactory<MutationFactory> */
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'ledger_id',
|
|
'user_id',
|
|
'type',
|
|
'amount',
|
|
'description',
|
|
'status',
|
|
];
|
|
|
|
public function ledger(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ledger::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function chat(): MorphOne
|
|
{
|
|
return $this->morphOne(Chat::class, 'chatable');
|
|
}
|
|
|
|
public function media(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable');
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function (Mutation $mutation) {
|
|
$mutation->chat()->create([]);
|
|
});
|
|
}
|
|
}
|