Files
root 79320950e7 Initial commit: Runware-powered content generator foundation
Laravel app with a cost-tracked Runware.ai integration (image, video,
text generation), a hard monthly EUR budget cap with live USD/EUR FX
conversion, and a locally-maintained model/pricing table since
Runware's model-search API doesn't expose pricing.
2026-09-23 15:59:05 +03:00

56 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RunwareModel extends Model
{
protected $fillable = [
'modality',
'air_id',
'label',
'unit',
'price_usd',
'is_default',
'active',
];
protected function casts(): array
{
return [
'price_usd' => 'decimal:6',
'is_default' => 'boolean',
'active' => 'boolean',
];
}
public static function defaultFor(string $modality): ?self
{
return static::query()
->where('modality', $modality)
->where('is_default', true)
->where('active', true)
->first();
}
/**
* The cheapest active model always wins the default flag, since Runware's
* own model-search API doesn't expose pricing — this locally-entered
* table is the only place "cheapest" can be computed from.
*/
public static function recomputeDefault(string $modality): void
{
static::query()->where('modality', $modality)->update(['is_default' => false]);
$cheapest = static::query()
->where('modality', $modality)
->where('active', true)
->orderBy('price_usd')
->orderBy('id')
->first();
$cheapest?->update(['is_default' => true]);
}
}