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:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 10:19:51 +02:00
1 parent 27ea12901e
commit bb7eb62782
53 files changed
+1963 -1

No files matched your search

+48
View File
@@ -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;
}
}
+27
View File
@@ -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',
};
}
}
+31
View File
@@ -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',
};
}
}
+21
View File
@@ -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',
};
}
}
+140
View File
@@ -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(),
]),
]);
}
}
+41
View File
@@ -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);
}
}
+12
View File
@@ -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 {}
+39
View File
@@ -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');
}
}
+51
View File
@@ -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()));
}
}
+95
View File
@@ -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(', ');
}
}
+8
View File
@@ -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>
*/
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Enums\UserRole;
class AmenityPolicy extends RolePolicy
{
protected function roles(): array
{
return [UserRole::Content];
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Enums\UserRole;
class FaqPolicy extends RolePolicy
{
protected function roles(): array
{
return [UserRole::Content];
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Enums\UserRole;
class NoticePolicy extends RolePolicy
{
protected function roles(): array
{
return [UserRole::Content];
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Enums\UserRole;
class PhotoPolicy extends RolePolicy
{
protected function roles(): array
{
return [UserRole::Content];
}
}
+87
View File
@@ -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());
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
/*
|--------------------------------------------------------------------------
| Editable website texts
|--------------------------------------------------------------------------
|
| Every field becomes an input on the admin page "Webseiten-Texte", grouped
| by section. Types: text, textarea, richtext (sanitised HTML), photo (id of
| a Photo). The default is shown until a value has been saved.
|
*/
return [
'home' => [
'label' => 'Startseite',
'fields' => [
'home.hero.eyebrow' => ['label' => 'Kleine Überschrift', 'type' => 'text', 'default' => 'Ostseebad Kühlungsborn'],
'home.hero.title' => ['label' => 'Hauptüberschrift', 'type' => 'text', 'default' => 'Ihr Zuhause zwischen Garten und Meer'],
'home.hero.text' => ['label' => 'Einleitungstext', 'type' => 'textarea', 'default' => '53 m² im Erdgeschoss, eigene Terrasse mit Blick auf Teich und Garten – ruhig gelegen in der Strandstraße.'],
'home.hero.photo' => ['label' => 'Titelbild', 'type' => 'photo'],
'home.intro.title' => ['label' => 'Abschnitt „Die Wohnung“: Überschrift', 'type' => 'text', 'default' => 'Ankommen, Tür auf, Terrasse – und durchatmen.'],
'home.intro.text' => ['label' => 'Abschnitt „Die Wohnung“: Text', 'type' => 'richtext', 'default' => '<p>Helles Wohnzimmer mit Ledersofa und Schrankbett, ein ruhiges Schlafzimmer mit Verdunkelung, eine voll ausgestattete Küche mit Geschirrspüler und ein Bad mit bodennaher Dusche.</p>'],
'home.location.title' => ['label' => 'Abschnitt „Lage“: Überschrift', 'type' => 'text', 'default' => 'Kühlungsborn – Strand, Hafen und Bäderarchitektur.'],
'home.location.text' => ['label' => 'Abschnitt „Lage“: Text', 'type' => 'richtext', 'default' => '<p>Zu Fuß an die Ostsee, zum Bootshafen in Kühlungsborn Ost oder mit der Dampflok „Molli“ nach Bad Doberan.</p>'],
],
],
'apartment' => [
'label' => 'Die Wohnung',
'fields' => [
'apartment.title' => ['label' => 'Überschrift', 'type' => 'text', 'default' => 'Die Wohnung'],
'apartment.text' => ['label' => 'Beschreibung', 'type' => 'richtext', 'default' => '<p>Unsere 53 m² große Ferienwohnung liegt im Erdgeschoss und bietet Platz für ein bis drei Personen. Wohnzimmer, Schlafzimmer, Küche mit Essbereich, Diele, Bad und eine eigene Terrasse mit Blick auf Teich und Garten.</p>'],
'apartment.floorplan' => ['label' => 'Grundriss', 'type' => 'photo'],
],
],
'area' => [
'label' => 'Kühlungsborn',
'fields' => [
'area.title' => ['label' => 'Überschrift', 'type' => 'text', 'default' => 'Kühlungsborn & Umgebung'],
'area.text' => ['label' => 'Text', 'type' => 'richtext', 'default' => '<p>Kühlungsborn ist eines der schönsten Ostseebäder – mit breitem Sandstrand, Strandpromenade, Bootshafen und prachtvoller Bäderarchitektur.</p>'],
],
],
'host' => [
'label' => 'Gastgeber',
'fields' => [
'host.quote' => ['label' => 'Zitat', 'type' => 'textarea', 'default' => 'Wir vermieten unsere Wohnung seit über 20 Jahren – und freuen uns jedes Mal, wenn Gäste wiederkommen.'],
'host.text' => ['label' => 'Text', 'type' => 'richtext', 'default' => '<p>Sie erreichen uns persönlich per Telefon oder E-Mail.</p>'],
'host.photo' => ['label' => 'Foto der Gastgeberin', 'type' => 'photo'],
],
],
'stay' => [
'label' => 'Aufenthalt',
'fields' => [
'stay.house_rules' => ['label' => 'Hausregeln', 'type' => 'richtext', 'default' => null],
'stay.arrival_info' => ['label' => 'Anreiseinformationen (für Gäste-E-Mail vor Anreise)', 'type' => 'richtext', 'default' => null],
'stay.cancellation' => ['label' => 'Stornobedingungen', 'type' => 'richtext', 'default' => null],
],
],
'legal' => [
'label' => 'Rechtliches',
'fields' => [
'legal.imprint' => ['label' => 'Impressum', 'type' => 'richtext', 'default' => null],
'legal.privacy' => ['label' => 'Datenschutzerklärung', 'type' => 'richtext', 'default' => null],
],
],
'seo' => [
'label' => 'Suchmaschinen',
'fields' => [
'seo.home.title' => ['label' => 'Seitentitel (Google)', 'type' => 'text', 'default' => 'Ferienwohnung Stommer in Kühlungsborn – Terrasse, Garten, Ostsee'],
'seo.home.description' => ['label' => 'Beschreibung (Google)', 'type' => 'textarea', 'default' => 'Gemütliche 53 m² Ferienwohnung im Erdgeschoss mit eigener Terrasse in Kühlungsborn. Freie Termine und Preise online prüfen und unverbindlich anfragen.'],
],
],
];
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace Database\Factories;
use App\Enums\AmenityArea;
use App\Models\Amenity;
use App\Models\Property;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Amenity>
*/
class AmenityFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'property_id' => Property::factory(),
'area' => AmenityArea::General,
'name' => fake()->words(2, true),
'is_highlight' => false,
'sort_order' => 0,
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use App\Models\Faq;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Faq>
*/
class FaqFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'question' => fake()->sentence().'?',
'answer' => '<p>'.fake()->paragraph().'</p>',
'is_published' => true,
'sort_order' => 0,
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use App\Enums\NoticeTone;
use App\Models\Notice;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Notice>
*/
class NoticeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'text' => fake()->sentence(),
'tone' => NoticeTone::Info,
'is_active' => true,
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Enums\PhotoCategory;
use App\Models\Photo;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Photo>
*/
class PhotoFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'category' => PhotoCategory::Apartment,
'alt_text' => fake()->sentence(3),
'is_published' => true,
'sort_order' => 0,
];
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('photos', function (Blueprint $table) {
$table->id();
$table->foreignId('property_id')->nullable()->constrained()->nullOnDelete();
$table->string('category');
$table->string('alt_text');
$table->string('caption')->nullable();
$table->boolean('is_published')->default(true);
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('photos');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('content_blocks', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->longText('value')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('content_blocks');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('faqs', function (Blueprint $table) {
$table->id();
$table->string('question');
$table->text('answer');
$table->boolean('is_published')->default(true);
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('faqs');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('amenities', function (Blueprint $table) {
$table->id();
$table->foreignId('property_id')->constrained()->cascadeOnDelete();
$table->string('area');
$table->string('name');
$table->boolean('is_highlight')->default(false);
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('amenities');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notices', function (Blueprint $table) {
$table->id();
$table->string('text');
$table->string('tone')->default('info');
$table->string('link_url')->nullable();
$table->string('link_label')->nullable();
$table->date('starts_on')->nullable();
$table->date('ends_on')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notices');
}
};
+1 -1
View File
@@ -22,6 +22,6 @@ public function run(): void
'role' => UserRole::Admin,
]);
$this->call(PropertySeeder::class);
$this->call([PropertySeeder::class, WebsiteContentSeeder::class]);
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace Database\Seeders;
use App\Enums\AmenityArea;
use App\Models\Faq;
use App\Models\Property;
use Illuminate\Database\Seeder;
/**
* Equipment list and FAQ taken over from the previous website. Only facts stated there.
*/
class WebsiteContentSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$property = Property::query()->firstOrFail();
$amenities = [
AmenityArea::General->value => ['Schnelles WLAN kostenlos', 'Pkw-Stellplatz inklusive', 'Abschließbarer Fahrradraum für 2 Räder', 'Diele mit großem Kleiderschrank und Spiegeln'],
AmenityArea::LivingRoom->value => ['Ledersofa und Sessel', 'Schrankbett 1,40 × 2,00 m', 'Kabel-TV', 'DVD-Player', 'HiFi-Anlage und Radio', 'Kleiner Schreibtisch'],
AmenityArea::Bedroom->value => ['Kingsize-Bett 1,80 m mit zwei Matratzen', 'Verdunkelungsrollo', 'Radiowecker', 'Nachttische mit Leselampen'],
AmenityArea::Kitchen->value => ['Einbauküche mit Backofen und Ceranfeld', 'Geschirrspüler', 'Mikrowelle', 'Kühlschrank mit großem Gefrierschrank', 'Kaffeemaschine, Wasserkocher, Toaster, Eierkocher', 'Esstisch mit Stühlen'],
AmenityArea::Bathroom->value => ['Dusche 90 × 90 cm mit niedrigem Einstieg', 'Beleuchteter Spiegelschrank', 'WC mit Sitzerhöhung', 'Föhn', 'Handtuchheizkörper'],
AmenityArea::Outdoor->value => ['Eigene Terrasse mit Gartenmöbeln', 'Blick auf Teich und Garten'],
];
$highlights = ['Schnelles WLAN kostenlos', 'Pkw-Stellplatz inklusive', 'Eigene Terrasse mit Gartenmöbeln', 'Kingsize-Bett 1,80 m mit zwei Matratzen', 'Geschirrspüler', 'Dusche 90 × 90 cm mit niedrigem Einstieg'];
$sort = 0;
foreach ($amenities as $area => $names) {
foreach ($names as $name) {
$property->amenities()->create([
'area' => $area,
'name' => $name,
'is_highlight' => in_array($name, $highlights, true),
'sort_order' => ++$sort,
]);
}
}
$faqs = [
'Was ist im Preis enthalten?' => '<p>Nebenkosten, WLAN, ein Pkw-Stellplatz und ein abschließbarer Fahrradraum für zwei Räder. Die Endreinigung wird einmalig pro Aufenthalt berechnet und ist im angezeigten Gesamtpreis enthalten.</p>',
'Kann ich Bettwäsche und Handtücher dazubuchen?' => '<p>Ja. Bettwäsche (die Betten sind bei Anreise bezogen) und Handtuchpakete können Sie bei der Anfrage auswählen.</p>',
'Wie viele Personen können übernachten?' => '<p>Die Wohnung ist für ein bis drei Personen geeignet: Kingsize-Bett im Schlafzimmer und ein Schrankbett im Wohnzimmer.</p>',
'Ist die Kurtaxe im Preis enthalten?' => '<p>Nein, die Kurtaxe der Gemeinde Kühlungsborn wird vor Ort bezahlt.</p>',
'Wie läuft die Bezahlung?' => '<p>Nach unserer Buchungsbestätigung überweisen Sie eine Anzahlung; der Restbetrag ist vier Wochen vor Anreise fällig.</p>',
'Ist meine Anfrage verbindlich?' => '<p>Nein. Wir merken den Termin für Sie vor und bestätigen kurzfristig. Erst mit unserer Bestätigung wird die Buchung verbindlich.</p>',
];
$sort = 0;
foreach ($faqs as $question => $answer) {
Faq::create(['question' => $question, 'answer' => $answer, 'sort_order' => ++$sort]);
}
}
}
+106
View File
@@ -0,0 +1,106 @@
<?php
namespace Tests\Feature;
use App\Enums\PhotoCategory;
use App\Enums\UserRole;
use App\Filament\Pages\EditContent;
use App\Filament\Resources\Amenities\AmenityResource;
use App\Filament\Resources\Faqs\FaqResource;
use App\Filament\Resources\Notices\NoticeResource;
use App\Filament\Resources\Photos\Pages\ListPhotos;
use App\Filament\Resources\Photos\PhotoResource;
use App\Filament\Resources\Properties\PropertyResource;
use App\Models\Amenity;
use App\Models\Notice;
use App\Models\Photo;
use App\Models\User;
use App\Support\Content;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class WebsiteContentTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
$this->seed([PropertySeeder::class, WebsiteContentSeeder::class]);
$this->actingAs(User::factory()->role(UserRole::Content)->create());
}
public function test_content_editor_sees_website_areas_but_not_bookings(): void
{
foreach ([PhotoResource::class, AmenityResource::class, FaqResource::class, NoticeResource::class] as $resource) {
$this->get($resource::getUrl('index'))->assertOk();
}
$this->get(EditContent::getUrl())->assertOk()->assertSee('Webseiten-Texte');
$this->get(PropertyResource::getUrl('index'))->assertForbidden();
}
public function test_texts_fall_back_to_defaults_and_can_be_saved(): void
{
$this->assertSame('Ihr Zuhause zwischen Garten und Meer', Content::get('home.hero.title'));
Livewire::test(EditContent::class)
->set('data.home__hero__title', 'Willkommen an der Ostsee')
->set('data.legal__imprint', '<p>Angaben gemäß § 5 DDG</p><script>alert(1)</script>')
->call('save')
->assertNotified('Texte gespeichert');
$this->assertSame('Willkommen an der Ostsee', Content::get('home.hero.title'));
$this->assertStringContainsString('§ 5 DDG', (string) Content::html('legal.imprint'));
$this->assertStringNotContainsString('<script>', (string) Content::html('legal.imprint'));
}
public function test_uploaded_photos_get_webp_web_sizes(): void
{
$photo = Photo::factory()->create();
$photo->addMedia(UploadedFile::fake()->image('terrasse.jpg', 3000, 2000))->toMediaCollection(Photo::COLLECTION);
$media = $photo->fresh()->getFirstMedia(Photo::COLLECTION);
foreach (array_keys(Photo::WIDTHS) as $conversion) {
$this->assertTrue($media->hasGeneratedConversion($conversion), "conversion {$conversion}");
$this->assertStringEndsWith('.webp', $photo->url($conversion));
}
$this->assertStringContainsString('2048w', $photo->srcset());
}
public function test_several_photos_are_uploaded_at_once(): void
{
Livewire::test(ListPhotos::class)
->callAction('bulkUpload', [
'files' => [UploadedFile::fake()->image('wohn-zimmer.jpg', 1600, 1000), UploadedFile::fake()->image('kueche.jpg', 1600, 1000)],
'category' => PhotoCategory::Apartment->value,
])
->assertNotified('2 Bilder hochgeladen');
$this->assertSame(['Wohn zimmer', 'Kueche'], Photo::orderBy('sort_order')->pluck('alt_text')->all());
}
public function test_notices_are_visible_only_within_their_dates(): void
{
$this->travelTo(CarbonImmutable::parse('2026-11-10'));
Notice::factory()->create(['text' => 'aktuell', 'starts_on' => '2026-11-01', 'ends_on' => '2026-11-15']);
Notice::factory()->create(['text' => 'vorbei', 'ends_on' => '2026-11-09']);
Notice::factory()->create(['text' => 'inaktiv', 'is_active' => false]);
Notice::factory()->create(['text' => 'dauerhaft']);
$this->assertEqualsCanonicalizing(['aktuell', 'dauerhaft'], Notice::visible()->pluck('text')->all());
}
public function test_amenities_from_the_old_website_are_seeded(): void
{
$this->assertGreaterThan(20, Amenity::count());
$this->assertSame(6, Amenity::where('is_highlight', true)->count());
}
}