Files
many-notes/app/Models/Vault.php
2025-01-26 18:57:20 +00:00

57 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Observers\VaultObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
#[ObservedBy([VaultObserver::class])]
final class Vault extends Model
{
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'templates_node_id',
'name',
];
/**
* Get the associated user.
*
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* Get the nodes for the vault.
*
* @return HasMany<VaultNode, $this>
*/
public function nodes(): HasMany
{
return $this->hasMany(VaultNode::class);
}
/**
* Get the associated templates node.
*
* @return HasOne<VaultNode, $this>
*/
public function templatesNode(): HasOne
{
return $this->hasOne(VaultNode::class, 'id', 'templates_node_id');
}
}