47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\GenerationCreditTransactionType;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class GenerationCreditTransaction extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\GenerationCreditTransactionFactory> */
|
|
use HasFactory, HasUlids;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'amount',
|
|
'type',
|
|
'source_type',
|
|
'source_id',
|
|
'idempotency_key',
|
|
'daily_reward_key',
|
|
'metadata',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function source(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount' => 'integer',
|
|
'type' => GenerationCreditTransactionType::class,
|
|
'metadata' => 'array',
|
|
];
|
|
}
|
|
}
|