Wohnungsumschalter im Verwaltungsmenue und wohnungsbezogene Listen

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>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-29 18:40:13 +01:00
1 parent e74033a958
commit 8bcda9a4bc
37 files changed
+520 -35

No files matched your search

@@ -0,0 +1,33 @@
<?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);
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Filament\Concerns;
use App\Models\Property;
use App\Support\CurrentProperty;
use Closure;
use Illuminate\Database\Eloquent\Model;
/**
* Opening a record of another apartment (e.g. from a notification e-mail) switches the admin to that apartment,
* so the menu always shows the apartment the open record belongs to.
*/
trait SelectsRecordProperty
{
public static function resolveRecordRouteBinding(int|string $key, ?Closure $modifyQuery = null): ?Model
{
$record = parent::resolveRecordRouteBinding($key, $modifyQuery);
$propertyId = $record !== null ? static::recordPropertyId($record) : null;
if ($propertyId !== null && $propertyId !== app(CurrentProperty::class)->id() && ($property = Property::query()->find($propertyId))) {
app(CurrentProperty::class)->select($property);
}
return $record;
}
public static function recordPropertyId(Model $record): ?int
{
$id = $record->getAttribute('property_id');
return $id !== null ? (int) $id : null;
}
}