Inhaltsverwaltung: Bilder, Webseiten-Texte, Ausstattung, FAQ, Hinweis-Banner
- Bilder mit automatischen WebP-Webgrößen (640/1280/2048 px), Sortierung per Drag & Drop, Mehrfach-Upload, Import-Befehl photos:import - Webseiten-Texte als feste, bearbeitbare Bausteine (config/content.php), Rich-Text bereinigt ausgegeben - Ausstattung und FAQ aus der bisherigen Webseite übernommen - Rolle Inhalte hat Zugriff auf alle Webseiten-Bereiche Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27ea12901e
commit
bb7eb62782
53 files changed
+1963
-1
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Property;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Signature('photos:import {directory : Folder with JPG/PNG/WebP files} {--category=apartment : apartment, outdoor or area}')]
|
||||
#[Description('Import all images of a folder as website photos (e.g. when migrating from the old website)')]
|
||||
class ImportPhotos extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$category = PhotoCategory::tryFrom((string) $this->option('category'));
|
||||
if ($category === null) {
|
||||
$this->error('Unbekannte Kategorie. Erlaubt: '.implode(', ', array_column(PhotoCategory::cases(), 'value')));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$files = glob(rtrim((string) $this->argument('directory'), '/\\').'/*.{jpg,jpeg,png,webp,JPG,JPEG,PNG,WEBP}', GLOB_BRACE) ?: [];
|
||||
$propertyId = $category === PhotoCategory::Area ? null : Property::query()->value('id');
|
||||
$sort = (int) Photo::max('sort_order');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$photo = Photo::create([
|
||||
'property_id' => $propertyId,
|
||||
'category' => $category,
|
||||
'alt_text' => str(pathinfo($file, PATHINFO_FILENAME))->replace(['_', '-'], ' ')->squish()->ucfirst()->toString(),
|
||||
'sort_order' => ++$sort,
|
||||
]);
|
||||
$photo->addMedia($file)->preservingOriginal()->toMediaCollection(Photo::COLLECTION);
|
||||
|
||||
$this->line("✓ {$photo->alt_text}");
|
||||
}
|
||||
|
||||
$this->info(count($files).' Bilder importiert.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum AmenityArea: string implements HasLabel
|
||||
{
|
||||
case General = 'general';
|
||||
case LivingRoom = 'living_room';
|
||||
case Bedroom = 'bedroom';
|
||||
case Kitchen = 'kitchen';
|
||||
case Bathroom = 'bathroom';
|
||||
case Outdoor = 'outdoor';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::General => 'Allgemein',
|
||||
self::LivingRoom => 'Wohnzimmer',
|
||||
self::Bedroom => 'Schlafzimmer',
|
||||
self::Kitchen => 'Küche',
|
||||
self::Bathroom => 'Bad',
|
||||
self::Outdoor => 'Terrasse & Außenbereich',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum NoticeTone: string implements HasColor, HasLabel
|
||||
{
|
||||
case Info = 'info';
|
||||
case Offer = 'offer';
|
||||
case Important = 'important';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Info => 'Information',
|
||||
self::Offer => 'Angebot',
|
||||
self::Important => 'Wichtig',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Info => 'info',
|
||||
self::Offer => 'success',
|
||||
self::Important => 'warning',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum PhotoCategory: string implements HasLabel
|
||||
{
|
||||
case Apartment = 'apartment';
|
||||
case Outdoor = 'outdoor';
|
||||
case Area = 'area';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Apartment => 'Wohnung',
|
||||
self::Outdoor => 'Terrasse & Garten',
|
||||
self::Area => 'Kühlungsborn & Umgebung',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\Photo;
|
||||
use App\Support\Content;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
use Filament\Schemas\Components\EmbeddedSchema;
|
||||
use Filament\Schemas\Components\Form;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* One form for all editable website texts from config/content.php, one tab per section.
|
||||
*
|
||||
* @property-read Schema $form
|
||||
*/
|
||||
class EditContent extends Page
|
||||
{
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPencilSquare;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $navigationLabel = 'Texte';
|
||||
|
||||
protected static ?string $title = 'Webseiten-Texte';
|
||||
|
||||
protected static ?string $slug = 'texte';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
/** @var array<string, ?string> */
|
||||
public array $data = [];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return (bool) auth()->user()?->hasRole(UserRole::Admin, UserRole::Content);
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$values = [];
|
||||
foreach (Content::sections() as $section) {
|
||||
foreach (array_keys($section['fields']) as $key) {
|
||||
$values[self::fieldName($key)] = Content::get($key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->form->fill($values);
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->statePath('data')
|
||||
->components([
|
||||
Tabs::make('sections')
|
||||
->persistTabInQueryString()
|
||||
->tabs(collect(Content::sections())
|
||||
->map(fn (array $section): Tab => Tab::make($section['label'])->schema(
|
||||
collect($section['fields'])->map(fn (array $field, string $key) => $this->field($key, $field))->values()->all(),
|
||||
))
|
||||
->values()
|
||||
->all()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Form::make([EmbeddedSchema::make('form')])
|
||||
->id('form')
|
||||
->livewireSubmitHandler('save')
|
||||
->footer([
|
||||
Actions::make([
|
||||
Action::make('save')->label('Speichern')->submit('save')->keyBindings(['mod+s']),
|
||||
])->sticky(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
|
||||
$values = [];
|
||||
foreach (Content::sections() as $section) {
|
||||
foreach (array_keys($section['fields']) as $key) {
|
||||
$value = $state[self::fieldName($key)] ?? null;
|
||||
$values[$key] = $value === null ? null : (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
Content::save($values);
|
||||
|
||||
Notification::make()->title('Texte gespeichert')->success()->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{label: string, type: string, default?: ?string} $field
|
||||
*/
|
||||
private function field(string $key, array $field): TextInput|Textarea|RichEditor|Select
|
||||
{
|
||||
$name = self::fieldName($key);
|
||||
|
||||
return match ($field['type']) {
|
||||
'textarea' => Textarea::make($name)->label($field['label'])->rows(3),
|
||||
'richtext' => RichEditor::make($name)
|
||||
->label($field['label'])
|
||||
->toolbarButtons([['bold', 'italic', 'link'], ['h2', 'h3'], ['bulletList', 'orderedList'], ['undo', 'redo']]),
|
||||
'photo' => Select::make($name)
|
||||
->label($field['label'])
|
||||
->options(fn (): array => Photo::query()->orderBy('category')->orderBy('sort_order')->pluck('alt_text', 'id')->all())
|
||||
->searchable()
|
||||
->placeholder('Kein Bild gewählt')
|
||||
->helperText('Bilder verwalten Sie unter „Webseite › Bilder“.'),
|
||||
default => TextInput::make($name)->label($field['label'])->maxLength(255),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Dots would be read as nested state, so content keys are flattened for the form.
|
||||
*/
|
||||
private static function fieldName(string $key): string
|
||||
{
|
||||
return str_replace('.', '__', $key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities;
|
||||
|
||||
use App\Filament\Resources\Amenities\Pages\CreateAmenity;
|
||||
use App\Filament\Resources\Amenities\Pages\EditAmenity;
|
||||
use App\Filament\Resources\Amenities\Pages\ListAmenities;
|
||||
use App\Filament\Resources\Amenities\Schemas\AmenityForm;
|
||||
use App\Filament\Resources\Amenities\Tables\AmenitiesTable;
|
||||
use App\Models\Amenity;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class AmenityResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Amenity::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedListBullet;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Ausstattungsmerkmal';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Ausstattung';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return AmenityForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return AmenitiesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAmenities::route('/'),
|
||||
'create' => CreateAmenity::route('/create'),
|
||||
'edit' => EditAmenity::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAmenity extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAmenity extends EditRecord
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAmenities extends ListRecords
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Schemas;
|
||||
|
||||
use App\Enums\AmenityArea;
|
||||
use App\Models\Property;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AmenityForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label('Ausstattung')
|
||||
->placeholder('z. B. Geschirrspüler')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('area')
|
||||
->label('Bereich')
|
||||
->options(AmenityArea::class)
|
||||
->required(),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Property::query()->value('id'))
|
||||
->required(),
|
||||
Toggle::make('is_highlight')
|
||||
->label('Highlight (auf der Startseite hervorheben)'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Tables;
|
||||
|
||||
use App\Enums\AmenityArea;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Grouping\Group;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AmenitiesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->defaultGroup(Group::make('area')->label('Bereich')->getTitleFromRecordUsing(fn ($record): string => $record->area->getLabel()))
|
||||
->paginated(false)
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Ausstattung')->searchable(),
|
||||
ToggleColumn::make('is_highlight')->label('Highlight'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('area')->label('Bereich')->options(AmenityArea::class),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs;
|
||||
|
||||
use App\Filament\Resources\Faqs\Pages\CreateFaq;
|
||||
use App\Filament\Resources\Faqs\Pages\EditFaq;
|
||||
use App\Filament\Resources\Faqs\Pages\ListFaqs;
|
||||
use App\Filament\Resources\Faqs\Schemas\FaqForm;
|
||||
use App\Filament\Resources\Faqs\Tables\FaqsTable;
|
||||
use App\Models\Faq;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class FaqResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Faq::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedQuestionMarkCircle;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Frage';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Häufige Fragen';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return FaqForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return FaqsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListFaqs::route('/'),
|
||||
'create' => CreateFaq::route('/create'),
|
||||
'edit' => EditFaq::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateFaq extends CreateRecord
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditFaq extends EditRecord
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListFaqs extends ListRecords
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Schemas;
|
||||
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class FaqForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('question')
|
||||
->label('Frage')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
RichEditor::make('answer')
|
||||
->label('Antwort')
|
||||
->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList']])
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Toggle::make('is_published')
|
||||
->label('Veröffentlicht')
|
||||
->default(true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Tables;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class FaqsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->paginated(false)
|
||||
->columns([
|
||||
TextColumn::make('question')->label('Frage')->searchable()->wrap(),
|
||||
ToggleColumn::make('is_published')->label('Veröffentlicht'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices;
|
||||
|
||||
use App\Filament\Resources\Notices\Pages\CreateNotice;
|
||||
use App\Filament\Resources\Notices\Pages\EditNotice;
|
||||
use App\Filament\Resources\Notices\Pages\ListNotices;
|
||||
use App\Filament\Resources\Notices\Schemas\NoticeForm;
|
||||
use App\Filament\Resources\Notices\Tables\NoticesTable;
|
||||
use App\Models\Notice;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class NoticeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Notice::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedMegaphone;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Hinweis';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Hinweis-Banner';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return NoticeForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return NoticesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListNotices::route('/'),
|
||||
'create' => CreateNotice::route('/create'),
|
||||
'edit' => EditNotice::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateNotice extends CreateRecord
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditNotice extends EditRecord
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListNotices extends ListRecords
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Schemas;
|
||||
|
||||
use App\Enums\NoticeTone;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class NoticeForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('text')
|
||||
->label('Hinweistext')
|
||||
->placeholder('z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
Select::make('tone')
|
||||
->label('Art')
|
||||
->options(NoticeTone::class)
|
||||
->default(NoticeTone::Info)
|
||||
->required(),
|
||||
Toggle::make('is_active')
|
||||
->label('Aktiv')
|
||||
->default(true)
|
||||
->inline(false),
|
||||
DatePicker::make('starts_on')
|
||||
->label('Anzeigen ab (optional)'),
|
||||
DatePicker::make('ends_on')
|
||||
->label('Anzeigen bis (optional)')
|
||||
->afterOrEqual('starts_on'),
|
||||
TextInput::make('link_label')
|
||||
->label('Link-Text (optional)')
|
||||
->placeholder('z. B. Jetzt anfragen')
|
||||
->maxLength(100),
|
||||
TextInput::make('link_url')
|
||||
->label('Link-Ziel (optional)')
|
||||
->placeholder('/buchen')
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Tables;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class NoticesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('starts_on', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('text')->label('Hinweis')->wrap()->searchable(),
|
||||
TextColumn::make('tone')->label('Art')->badge(),
|
||||
TextColumn::make('starts_on')->label('Ab')->date('d.m.Y')->placeholder('sofort'),
|
||||
TextColumn::make('ends_on')->label('Bis')->date('d.m.Y')->placeholder('unbegrenzt'),
|
||||
ToggleColumn::make('is_active')->label('Aktiv'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePhoto extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPhoto extends EditRecord
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Property;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
||||
class ListPhotos extends ListRecords
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('bulkUpload')
|
||||
->label('Mehrere Bilder hochladen')
|
||||
->icon(Heroicon::OutlinedArrowUpTray)
|
||||
->authorize('create', Photo::class)
|
||||
->modalDescription('Die Bildbeschreibung wird aus dem Dateinamen vorbelegt – bitte danach kurz anpassen.')
|
||||
->schema([
|
||||
FileUpload::make('files')
|
||||
->label('Bilder')
|
||||
->multiple()
|
||||
->image()
|
||||
->maxSize(25 * 1024)
|
||||
->storeFiles(false)
|
||||
->required(),
|
||||
Select::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class)
|
||||
->default(PhotoCategory::Apartment)
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$propertyId = Property::query()->value('id');
|
||||
$nextSort = (int) Photo::max('sort_order');
|
||||
|
||||
/** @var TemporaryUploadedFile $file */
|
||||
foreach ($data['files'] as $file) {
|
||||
$photo = Photo::create([
|
||||
'property_id' => $data['category'] === PhotoCategory::Area->value ? null : $propertyId,
|
||||
'category' => $data['category'],
|
||||
'alt_text' => str(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME))->replace(['_', '-'], ' ')->squish()->ucfirst()->toString(),
|
||||
'sort_order' => ++$nextSort,
|
||||
]);
|
||||
$photo->addMedia($file->getRealPath())
|
||||
->usingFileName($file->getClientOriginalName())
|
||||
->toMediaCollection(Photo::COLLECTION);
|
||||
}
|
||||
|
||||
Notification::make()->title(count($data['files']).' Bilder hochgeladen')->success()->send();
|
||||
}),
|
||||
CreateAction::make()->label('Einzelnes Bild'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos;
|
||||
|
||||
use App\Filament\Resources\Photos\Pages\CreatePhoto;
|
||||
use App\Filament\Resources\Photos\Pages\EditPhoto;
|
||||
use App\Filament\Resources\Photos\Pages\ListPhotos;
|
||||
use App\Filament\Resources\Photos\Schemas\PhotoForm;
|
||||
use App\Filament\Resources\Photos\Tables\PhotosTable;
|
||||
use App\Models\Photo;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class PhotoResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Photo::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPhoto;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Bild';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Bilder';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return PhotoForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return PhotosTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPhotos::route('/'),
|
||||
'create' => CreatePhoto::route('/create'),
|
||||
'edit' => EditPhoto::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Schemas;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Property;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class PhotoForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
SpatieMediaLibraryFileUpload::make('image')
|
||||
->label('Bild')
|
||||
->collection(Photo::COLLECTION)
|
||||
->image()
|
||||
->imageEditor()
|
||||
->maxSize(25 * 1024)
|
||||
->helperText('JPG, PNG oder WebP bis 25 MB. Große Originale sind willkommen – Web-Größen werden automatisch erzeugt.')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('alt_text')
|
||||
->label('Bildbeschreibung')
|
||||
->helperText('Kurz beschreiben, was zu sehen ist – wichtig für Google und für blinde Besucher.')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('caption')
|
||||
->label('Bildunterschrift (optional)')
|
||||
->maxLength(255),
|
||||
Select::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class)
|
||||
->default(PhotoCategory::Apartment)
|
||||
->required(),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Property::query()->value('id'))
|
||||
->placeholder('– keine (z. B. Umgebung) –'),
|
||||
Toggle::make('is_published')
|
||||
->label('Auf der Webseite zeigen')
|
||||
->default(true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Tables;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Models\Photo;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\Layout\Stack;
|
||||
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PhotosTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->contentGrid(['md' => 3, 'xl' => 4])
|
||||
->paginated([24, 48, 'all'])
|
||||
->columns([
|
||||
Stack::make([
|
||||
SpatieMediaLibraryImageColumn::make('image')
|
||||
->collection(Photo::COLLECTION)
|
||||
->conversion('sm')
|
||||
->imageHeight(180)
|
||||
->extraImgAttributes(['class' => 'w-full object-cover rounded-lg']),
|
||||
TextColumn::make('alt_text')
|
||||
->weight('medium')
|
||||
->searchable(),
|
||||
TextColumn::make('category')
|
||||
->badge(),
|
||||
IconColumn::make('is_published')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-eye')
|
||||
->falseIcon('heroicon-o-eye-slash'),
|
||||
])->space(2),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AmenityArea;
|
||||
use Database\Factories\AmenityFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* One line of the equipment list; highlights are featured on the home page.
|
||||
*/
|
||||
#[Fillable(['property_id', 'area', 'name', 'is_highlight', 'sort_order'])]
|
||||
class Amenity extends Model
|
||||
{
|
||||
/** @use HasFactory<AmenityFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'area' => AmenityArea::class,
|
||||
'is_highlight' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Value of an editable website text; the available keys are defined in config/content.php.
|
||||
*/
|
||||
#[Fillable(['key', 'value'])]
|
||||
class ContentBlock extends Model {}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\FaqFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
#[Fillable(['question', 'answer', 'is_published', 'sort_order'])]
|
||||
class Faq extends Model
|
||||
{
|
||||
/** @use HasFactory<FaqFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Faq> $query
|
||||
* @return Builder<Faq>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function published(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_published', true)->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\NoticeTone;
|
||||
use Database\Factories\NoticeFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* A banner shown on the website, optionally limited to a date range.
|
||||
*/
|
||||
#[Fillable(['text', 'tone', 'link_url', 'link_label', 'starts_on', 'ends_on', 'is_active'])]
|
||||
class Notice extends Model
|
||||
{
|
||||
/** @use HasFactory<NoticeFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'tone' => NoticeTone::class,
|
||||
'starts_on' => 'immutable_date',
|
||||
'ends_on' => 'immutable_date',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Active notices whose date range includes today.
|
||||
*
|
||||
* @param Builder<Notice> $query
|
||||
* @return Builder<Notice>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function visible(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->where('is_active', true)
|
||||
->where(fn (Builder $query) => $query->whereNull('starts_on')->orWhereDate('starts_on', '<=', today()))
|
||||
->where(fn (Builder $query) => $query->whereNull('ends_on')->orWhereDate('ends_on', '>=', today()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use Database\Factories\PhotoFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
/**
|
||||
* A website photo. The uploaded original is kept; web sizes are generated as WebP on upload.
|
||||
*/
|
||||
#[Fillable(['property_id', 'category', 'alt_text', 'caption', 'is_published', 'sort_order'])]
|
||||
class Photo extends Model implements HasMedia
|
||||
{
|
||||
/** @use HasFactory<PhotoFactory> */
|
||||
use HasFactory, InteractsWithMedia;
|
||||
|
||||
public const COLLECTION = 'image';
|
||||
|
||||
/** Generated widths in px, used for srcset. */
|
||||
public const WIDTHS = ['sm' => 640, 'md' => 1280, 'lg' => 2048];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'category' => PhotoCategory::class,
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection(self::COLLECTION)
|
||||
->singleFile()
|
||||
->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/webp']);
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
foreach (self::WIDTHS as $name => $width) {
|
||||
$this->addMediaConversion($name)
|
||||
->fit(Fit::Max, $width, $width)
|
||||
->format('webp')
|
||||
->quality(80)
|
||||
->performOnCollections(self::COLLECTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Photo> $query
|
||||
* @return Builder<Photo>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function published(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_published', true)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function url(string $size = 'md'): string
|
||||
{
|
||||
return $this->getFirstMediaUrl(self::COLLECTION, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* srcset for <img>, e.g. "…-sm.webp 640w, …-md.webp 1280w, …-lg.webp 2048w".
|
||||
*/
|
||||
public function srcset(): string
|
||||
{
|
||||
return collect(self::WIDTHS)
|
||||
->map(fn (int $width, string $name): string => $this->url($name).' '.$width.'w')
|
||||
->implode(', ');
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,14 @@ public function blockedPeriods(): HasMany
|
||||
return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Amenity, $this>
|
||||
*/
|
||||
public function amenities(): HasMany
|
||||
{
|
||||
return $this->hasMany(Amenity::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<SpecialOffer, $this>
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class AmenityPolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class FaqPolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class NoticePolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class PhotoPolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\ContentBlock;
|
||||
use App\Models\Photo;
|
||||
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Read access to the editable website texts defined in config/content.php.
|
||||
*/
|
||||
class Content
|
||||
{
|
||||
private const CACHE_KEY = 'content-blocks';
|
||||
|
||||
/**
|
||||
* The stored value, or the configured default when nothing was saved.
|
||||
*/
|
||||
public static function get(string $key): ?string
|
||||
{
|
||||
$definition = self::definition($key);
|
||||
$stored = self::stored()[$key] ?? null;
|
||||
|
||||
return filled($stored) ? $stored : ($definition['default'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rich text as sanitised HTML, ready for {{ }} output in Blade.
|
||||
*/
|
||||
public static function html(string $key): HtmlString
|
||||
{
|
||||
return new HtmlString(RichContentRenderer::make(self::get($key) ?? '')->toHtml());
|
||||
}
|
||||
|
||||
public static function photo(string $key): ?Photo
|
||||
{
|
||||
$id = self::get($key);
|
||||
|
||||
return $id ? Photo::find((int) $id) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ?string> $values
|
||||
*/
|
||||
public static function save(array $values): void
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
self::definition($key);
|
||||
ContentBlock::updateOrCreate(['key' => $key], ['value' => $value]);
|
||||
}
|
||||
|
||||
Cache::forget(self::CACHE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, fields: array<string, array{label: string, type: string, default?: ?string}>}>
|
||||
*/
|
||||
public static function sections(): array
|
||||
{
|
||||
return config('content');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{label: string, type: string, default?: ?string}
|
||||
*/
|
||||
private static function definition(string $key): array
|
||||
{
|
||||
foreach (self::sections() as $section) {
|
||||
if (isset($section['fields'][$key])) {
|
||||
return $section['fields'][$key];
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("Unknown content key [{$key}].");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ?string>
|
||||
*/
|
||||
private static function stored(): array
|
||||
{
|
||||
return Cache::rememberForever(self::CACHE_KEY, fn (): array => ContentBlock::pluck('value', 'key')->all());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user