trypost/app/Models/AiUsageLog.php
2026-04-15 21:06:06 -03:00

46 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Database\Factories\AiUsageLogFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AiUsageLog extends Model
{
/** @use HasFactory<AiUsageLogFactory> */
use HasFactory, HasUuids;
protected $fillable = [
'account_id',
'workspace_id',
'user_id',
'post_id',
'type',
'provider',
'metadata',
];
protected function casts(): array
{
return ['metadata' => 'array'];
}
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
public static function monthlyCount(string $accountId, string $type): int
{
return static::where('account_id', $accountId)
->where('type', $type)
->whereMonth('created_at', now()->month)
->whereYear('created_at', now()->year)
->count();
}
}