35 lines
869 B
PHP
35 lines
869 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
class Tenant extends Model
|
|
{
|
|
protected $table = 'tenants';
|
|
protected $guarded = [];
|
|
protected $casts = [
|
|
'features' => 'array',
|
|
'last_activity_at' => 'datetime',
|
|
];
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
|
|
public function photos(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
Photo::class,
|
|
Event::class,
|
|
'tenant_id', // Foreign key on events table...
|
|
'event_id', // Foreign key on photos table...
|
|
'id', // Local key on tenants table...
|
|
'id' // Local key on events table...
|
|
);
|
|
}
|
|
}
|