Files
fewo-stommer/app/Models/Tenant.php
T
LarsandCursor 8ebc1a3878 Assign the existing site to one landlord so stommer.info can run tenancy.
Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 12:00:11 +02:00

67 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Database\Factories\TenantFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* A landlord. Owns websites, apartments, guests, bookings and settings. One account can belong
* to several landlords; the operator is not a landlord.
*/
#[Fillable(['name', 'slug', 'is_active'])]
class Tenant extends Model
{
/** @use HasFactory<TenantFactory> */
use HasFactory;
/**
* The landlord the existing single-website data belongs to.
*/
public static function stommer(): self
{
return static::query()->firstOrCreate(
['slug' => 'stommer'],
['name' => 'Stommer'],
);
}
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_active' => 'boolean',
];
}
/**
* @return HasMany<Site, $this>
*/
public function sites(): HasMany
{
return $this->hasMany(Site::class);
}
/**
* @return HasMany<Property, $this>
*/
public function properties(): HasMany
{
return $this->hasMany(Property::class);
}
/**
* @return BelongsToMany<User, $this>
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)->withPivot('role')->withTimestamps();
}
}