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.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Generation extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'batch_id',
|
||||
'type',
|
||||
'model',
|
||||
'prompt',
|
||||
'params',
|
||||
'status',
|
||||
'runware_task_uuid',
|
||||
'cost_usd',
|
||||
'cost_eur',
|
||||
'cost_is_estimated',
|
||||
'output_path',
|
||||
'output_text',
|
||||
'error',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'params' => 'array',
|
||||
'cost_usd' => 'decimal:6',
|
||||
'cost_eur' => 'decimal:6',
|
||||
'cost_is_estimated' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user