Files
ladill-transfer/app/Models/Transfer.php
T
isaaccladandCursor e76955eaa4
Deploy Ladill Transfer / deploy (push) Successful in 40s
Reduce Transfer storage price to GHS 0.15 per GB per month.
Updates config default, env examples, and removes hardcoded GHS 1.00 copy on the dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 10:45:12 +00:00

85 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Transfer extends Model
{
public const STATUS_ACTIVE = 'active';
public const STATUS_EXPIRED = 'expired';
public const STATUS_DELETED = 'deleted';
protected $fillable = [
'user_id',
'qr_code_id',
'title',
'message',
'password_hash',
'retention_days',
'expires_at',
'status',
'downloads_total',
'storage_bytes',
];
protected $casts = [
'retention_days' => 'integer',
'expires_at' => 'datetime',
'downloads_total' => 'integer',
'storage_bytes' => 'integer',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function qrCode(): BelongsTo
{
return $this->belongsTo(QrCode::class);
}
public function files(): HasMany
{
return $this->hasMany(TransferFile::class);
}
public function downloadEvents(): HasMany
{
return $this->hasMany(TransferDownloadEvent::class);
}
public function isActive(): bool
{
if ($this->status !== self::STATUS_ACTIVE) {
return false;
}
if ($this->expires_at && $this->expires_at->isPast()) {
return false;
}
return true;
}
public function isPasswordProtected(): bool
{
return $this->password_hash !== null && $this->password_hash !== '';
}
public function storageGb(): float
{
return round($this->storage_bytes / (1024 * 1024 * 1024), 3);
}
public function monthlyCostGhs(): float
{
return round($this->storageGb() * (float) config('transfer.price_per_gb_month', 0.15), 2);
}
}