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,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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user