Files
fewo-stommer/app/Filament/Concerns/SelectsRecordProperty.php
T
LarsandClaude Opus 5.5 8bcda9a4bc 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>
2026-10-29 18:40:13 +01:00

35 lines
1.0 KiB
PHP

<?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;
}
}