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:
1 parent
e74033a958
commit
8bcda9a4bc
37 files changed
+520
-35
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user