CluPilotCloud/app/Models/ExportTarget.php

47 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* One place a copy of every invoice is written to.
*
* As many as somebody wants, because the reason for having a second is that
* the first can fail — an office NAS is unreachable while the office router
* reboots, and an off-site box is unreachable while somebody else's data centre
* has a bad morning.
*/
class ExportTarget extends Model
{
use HasUuid;
public const LOCAL = 'local';
public const SFTP = 'sftp';
protected $fillable = [
'name', 'driver', 'path', 'host', 'port', 'username', 'secret_key', 'active',
];
protected function casts(): array
{
return ['active' => 'boolean', 'port' => 'integer'];
}
public function exports(): HasMany
{
return $this->hasMany(InvoiceExport::class);
}
/** Human-readable, for a list and for an error message. */
public function describe(): string
{
return $this->driver === self::SFTP
? $this->username.'@'.$this->host.':'.$this->path
: $this->path;
}
}