Oben im Seitenmenue waehlt man die Wohnung; Listen, neue Eintraege, Belegungsplan und Preise & Angebote folgen ihr. Ein geoeffneter Eintrag einer anderen Wohnung schaltet auf diese um. Galerie und Ersatz-Titelbild der Website zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1012 B
PHP
34 lines
1012 B
PHP
<?php
|
|
|
|
namespace App\Filament\Concerns;
|
|
|
|
use App\Models\Property;
|
|
use App\Support\CurrentProperty;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
|
|
/**
|
|
* Limits a resource list to the apartment chosen in the admin menu (CurrentProperty).
|
|
* Records stay reachable by URL; opening one switches to its apartment (SelectsRecordProperty).
|
|
*/
|
|
trait ListsCurrentProperty
|
|
{
|
|
protected function getTableQuery(): Builder|Relation|null
|
|
{
|
|
$query = parent::getTableQuery();
|
|
$property = app(CurrentProperty::class)->get();
|
|
|
|
return $query instanceof Builder && $property !== null ? $this->scopeToProperty($query, $property) : $query;
|
|
}
|
|
|
|
/**
|
|
* @param Builder<Model> $query
|
|
* @return Builder<Model>
|
|
*/
|
|
protected function scopeToProperty(Builder $query, Property $property): Builder
|
|
{
|
|
return $query->where($query->qualifyColumn('property_id'), $property->id);
|
|
}
|
|
}
|