Lance Pioch 635cc6a029
Add PHP 8.4 Support (#858)
* Add php 8.4

* Update ide helper

* Add php 8.4

* Update laravel sanctum

* Update laravel framework

* Hash rounds were increased

* This is always false

* Extend model now

* This does nothing

* Move model validation methods to trait

* Remove base model

* Backup routes were previously referenced by uuids

* Remove commented code

* Upgrade laravel/framework

* Fix migration

* Update ide helper

* Update sanctum

* Add version to composer

* Add this back in, fixed

* Make this protected to be safer
2025-01-30 16:39:00 -05:00

119 lines
3.0 KiB
PHP

<?php
namespace App\Models;
use App\Contracts\Validatable;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rules\NotIn;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* @property int $id
* @property string $uuid
* @property string $name
* @property string $description
* @property string $source
* @property string $target
* @property bool $read_only
* @property bool $user_mountable
* @property \App\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
* @property \App\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
* @property \App\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
*/
class Mount extends Model implements Validatable
{
use HasValidation { getRules as getValidationRules; }
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
public const RESOURCE_NAME = 'mount';
/**
* Fields that are not mass assignable.
*/
protected $guarded = ['id'];
/**
* Rules verifying that the data being stored matches the expectations of the database.
*/
public static array $validationRules = [
'name' => 'required|string|min:2|max:64|unique:mounts,name',
'description' => 'nullable|string|max:255',
'source' => 'required|string',
'target' => 'required|string',
'read_only' => 'sometimes|boolean',
'user_mountable' => 'sometimes|boolean',
];
/**
* Implement language verification by overriding Eloquence's gather
* rules function.
*/
public static function getRules(): array
{
$rules = self::getValidationRules();
$rules['source'][] = new NotIn(Mount::$invalidSourcePaths);
$rules['target'][] = new NotIn(Mount::$invalidTargetPaths);
return $rules;
}
/**
* Disable timestamps on this model.
*/
public $timestamps = false;
/**
* Blacklisted source paths.
*/
public static array $invalidSourcePaths = [
'/etc/pelican',
'/var/lib/pelican/volumes',
'/srv/daemon-data',
];
/**
* Blacklisted target paths.
*/
public static array $invalidTargetPaths = [
'/home/container',
];
protected function casts(): array
{
return [
'id' => 'int',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
}
/**
* Returns all eggs that have this mount assigned.
*/
public function eggs(): BelongsToMany
{
return $this->belongsToMany(Egg::class);
}
/**
* Returns all nodes that have this mount assigned.
*/
public function nodes(): BelongsToMany
{
return $this->belongsToMany(Node::class);
}
/**
* Returns all servers that have this mount assigned.
*/
public function servers(): BelongsToMany
{
return $this->belongsToMany(Server::class);
}
}