Gästeverzeichnis und Customer Voice

- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist)
- Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks
- Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin
- Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit

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:26:11 +02:00
1 parent bb7eb62782
commit 2892e6aeab
44 files changed
+1505 -23

No files matched your search

+2
View File
@@ -71,3 +71,5 @@ FEWO_BANK_ACCOUNT_HOLDER=
FEWO_BANK_IBAN=
FEWO_BANK_BIC=
FEWO_BANK_NAME=
FEWO_REVIEW_REQUEST_AFTER_DAYS=2
FEWO_GUEST_RETENTION_YEARS=10
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Actions;
use App\Models\Guest;
/**
* Anonymises guests whose last stay ended longer ago than the retention period (GDPR storage limitation).
*/
class AnonymizeGuests
{
public function handle(): int
{
$cutoff = today()->subYears(config('fewo.guest_retention_years'));
$guests = Guest::query()
->whereNull('anonymized_at')
->whereDate('created_at', '<', $cutoff)
->whereDoesntHave('bookings', fn ($query) => $query->whereDate('departure', '>=', $cutoff))
->get();
$guests->each->anonymize();
return $guests->count();
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Actions;
use App\Mail\MarketingConsentRequest;
use App\Models\Guest;
use Illuminate\Support\Facades\Mail;
/**
* First step of the double opt-in: the guest receives a confirmation link.
*/
class RequestMarketingConsent
{
public function handle(Guest $guest): void
{
if ($guest->marketing_consent_at !== null || $guest->anonymized_at !== null) {
return;
}
Mail::to($guest->email, $guest->full_name)->send(new MarketingConsentRequest($guest));
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Mail\ReviewRequest;
use App\Models\Booking;
use Illuminate\Support\Facades\Mail;
/**
* Sends the review invitation once, a few days after departure. Old stays (more than 30 days ago)
* are skipped so that switching the feature on does not mail former guests.
*/
class RequestReviews
{
public function handle(): int
{
$latestDeparture = today()->subDays(config('fewo.review_request_after_days'));
$bookings = Booking::query()
->whereIn('status', BookingStatus::occupying())
->whereNull('review_requested_at')
->whereDate('departure', '<=', $latestDeparture)
->whereDate('departure', '>', $latestDeparture->copy()->subDays(30))
->whereDoesntHave('review')
->whereHas('guest', fn ($query) => $query->whereNull('anonymized_at'))
->with('guest')
->get();
foreach ($bookings as $booking) {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReviewRequest($booking));
$booking->update(['review_requested_at' => now()]);
}
return $bookings->count();
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Enums\ReviewStatus;
use App\Mail\NewReview;
use App\Models\Booking;
use App\Models\Review;
use Illuminate\Support\Facades\Mail;
use RuntimeException;
/**
* Stores a review written by a guest of a real, finished stay. It is published only after approval.
*/
class SubmitReview
{
/**
* @param array{rating: int, rating_cleanliness?: ?int, rating_equipment?: ?int, rating_location?: ?int, rating_host?: ?int, title?: ?string, body?: ?string, private_feedback?: ?string, display_name: string, publish_consent: bool} $data
*/
public function handle(Booking $booking, array $data): Review
{
if (! self::canReview($booking)) {
throw new RuntimeException('Für diese Buchung kann keine Bewertung abgegeben werden.');
}
$review = $booking->review()->create([
...$data,
'property_id' => $booking->property_id,
'status' => ReviewStatus::Pending,
'source' => 'website',
'stayed_on' => $booking->arrival,
]);
Mail::to(config('fewo.notification_email'))->send(new NewReview($review));
return $review;
}
public static function canReview(Booking $booking): bool
{
return in_array($booking->status, BookingStatus::occupying(), true)
&& $booking->departure->lessThanOrEqualTo(today())
&& ! $booking->review()->exists();
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Enums;
use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasLabel;
enum ReviewStatus: string implements HasColor, HasLabel
{
case Pending = 'pending';
case Approved = 'approved';
case Rejected = 'rejected';
public function getLabel(): string
{
return match ($this) {
self::Pending => 'Zu prüfen',
self::Approved => 'Freigegeben',
self::Rejected => 'Abgelehnt',
};
}
public function getColor(): string
{
return match ($this) {
self::Pending => 'warning',
self::Approved => 'success',
self::Rejected => 'gray',
};
}
}
@@ -5,6 +5,7 @@
use App\Filament\Resources\Guests\Pages\CreateGuest;
use App\Filament\Resources\Guests\Pages\EditGuest;
use App\Filament\Resources\Guests\Pages\ListGuests;
use App\Filament\Resources\Guests\RelationManagers\BookingsRelationManager;
use App\Filament\Resources\Guests\Schemas\GuestForm;
use App\Filament\Resources\Guests\Tables\GuestsTable;
use App\Models\Guest;
@@ -44,7 +45,7 @@ public static function table(Table $table): Table
public static function getRelations(): array
{
return [
//
BookingsRelationManager::class,
];
}
@@ -2,10 +2,17 @@
namespace App\Filament\Resources\Guests\Pages;
use App\Enums\UserRole;
use App\Filament\Resources\Guests\GuestResource;
use Filament\Actions\DeleteAction;
use App\Models\Guest;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Filament\Support\Icons\Heroicon;
/**
* @property Guest $record
*/
class EditGuest extends EditRecord
{
protected static string $resource = GuestResource::class;
@@ -13,7 +20,19 @@ class EditGuest extends EditRecord
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
Action::make('anonymize')
->label('Anonymisieren')
->icon(Heroicon::OutlinedEyeSlash)
->color('danger')
->visible(fn (): bool => $this->record->anonymized_at === null && (bool) auth()->user()?->hasRole(UserRole::Admin))
->requiresConfirmation()
->modalDescription('Name, Kontaktdaten, Notizen und Nachrichten werden unwiderruflich entfernt (z. B. auf Löschwunsch nach DSGVO). Buchungen und Beträge bleiben für die Buchhaltung erhalten.')
->action(function (): void {
$this->record->anonymize();
$this->refreshFormData(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'notes', 'tags']);
Notification::make()->title('Gast anonymisiert')->success()->send();
}),
];
}
}
@@ -3,8 +3,13 @@
namespace App\Filament\Resources\Guests\Pages;
use App\Filament\Resources\Guests\GuestResource;
use App\Models\Guest;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Icons\Heroicon;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ListGuests extends ListRecords
{
@@ -13,7 +18,52 @@ class ListGuests extends ListRecords
protected function getHeaderActions(): array
{
return [
Action::make('export')
->label('Export (Excel/CSV)')
->icon(Heroicon::OutlinedArrowDownTray)
->color('gray')
->schema([
Toggle::make('consent_only')->label('Nur Gäste mit Einwilligung für Angebote'),
])
->action(fn (array $data): StreamedResponse => $this->export($data['consent_only'])),
CreateAction::make(),
];
}
/**
* Semicolon-separated UTF-8 with BOM so that Excel opens umlauts correctly.
*/
private function export(bool $consentOnly): StreamedResponse
{
$guests = Guest::query()
->whereNull('anonymized_at')
->when($consentOnly, fn ($query) => $query->withMarketingConsent())
->withCount('bookings')
->orderBy('last_name')
->get();
return response()->streamDownload(function () use ($guests): void {
$out = fopen('php://output', 'w');
fwrite($out, "\xEF\xBB\xBF");
fputcsv($out, ['Vorname', 'Nachname', 'E-Mail', 'Telefon', 'Straße', 'PLZ', 'Ort', 'Land', 'Markierungen', 'Buchungen', 'Einwilligung Angebote'], ';');
foreach ($guests as $guest) {
fputcsv($out, [
$guest->first_name,
$guest->last_name,
$guest->email,
$guest->phone,
$guest->street,
$guest->postal_code,
$guest->city,
$guest->country,
implode(', ', $guest->tags ?? []),
$guest->bookings_count,
$guest->marketing_consent_at?->format('d.m.Y'),
], ';');
}
fclose($out);
}, 'gaeste-'.now()->format('Y-m-d').'.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Filament\Resources\Guests\RelationManagers;
use App\Filament\Resources\Bookings\BookingResource;
use App\Models\Booking;
use Filament\Actions\ViewAction;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class BookingsRelationManager extends RelationManager
{
protected static string $relationship = 'bookings';
protected static ?string $title = 'Aufenthalte & Anfragen';
public function isReadOnly(): bool
{
return true;
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('reference')
->columns([
TextColumn::make('reference')->label('Nr.'),
TextColumn::make('arrival')->label('Anreise')->date('d.m.Y'),
TextColumn::make('departure')->label('Abreise')->date('d.m.Y'),
TextColumn::make('guests')->label('Pers.'),
TextColumn::make('status')->label('Status')->badge(),
TextColumn::make('total')->label('Gesamt')->money('EUR', divideBy: 100, locale: 'de'),
])
->recordActions([
ViewAction::make()->url(fn (Booking $record): string => BookingResource::getUrl('view', ['record' => $record])),
]);
}
}
@@ -2,9 +2,13 @@
namespace App\Filament\Resources\Guests\Schemas;
use App\Models\Guest;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class GuestForm
@@ -12,21 +16,40 @@ class GuestForm
public static function configure(Schema $schema): Schema
{
return $schema
->columns(2)
->columns(3)
->components([
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
TextInput::make('email')->label('E-Mail')->email()->required()->maxLength(255),
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
TextInput::make('street')->label('Straße')->maxLength(255),
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
TextInput::make('city')->label('Ort')->maxLength(255),
Select::make('country')
->label('Land')
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
->default('DE')
->required(),
Textarea::make('notes')->label('Notizen')->columnSpanFull(),
Section::make('Kontakt')
->columnSpan(2)
->columns(2)
->schema([
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
TextInput::make('email')->label('E-Mail')->email()->required()->maxLength(255),
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
TextInput::make('street')->label('Straße')->maxLength(255),
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
TextInput::make('city')->label('Ort')->maxLength(255),
Select::make('country')
->label('Land')
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
->default('DE')
->required(),
]),
Section::make('Verwaltung')
->columnSpan(1)
->schema([
TagsInput::make('tags')
->label('Markierungen')
->suggestions(['Stammgast', 'Familie', 'Empfehlung', 'Nicht wieder vermieten']),
TextEntry::make('marketing_consent_at')
->label('Einwilligung Angebote per E-Mail')
->state(fn (?Guest $record): string => $record?->marketing_consent_at ? 'bestätigt am '.$record->marketing_consent_at->format('d.m.Y') : 'keine'),
TextEntry::make('anonymized_at')
->label('Anonymisiert')
->dateTime('d.m.Y')
->visible(fn (?Guest $record): bool => $record?->anonymized_at !== null),
Textarea::make('notes')->label('Notizen')->rows(5),
]),
]);
}
}
@@ -2,28 +2,54 @@
namespace App\Filament\Resources\Guests\Tables;
use App\Enums\BookingStatus;
use App\Models\Guest;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class GuestsTable
{
public static function configure(Table $table): Table
{
$countedBookings = ['bookings' => fn (Builder $query): Builder => $query->whereIn('status', BookingStatus::occupying())];
return $table
->defaultSort('last_name')
->columns([
TextColumn::make('last_name')
->label('Name')
->formatStateUsing(fn (Guest $record): string => "{$record->last_name}, {$record->first_name}")
->searchable(['first_name', 'last_name'])
->description(fn (Guest $record): string => $record->email)
->searchable(['first_name', 'last_name', 'email'])
->sortable(),
TextColumn::make('email')->label('E-Mail')->searchable(),
TextColumn::make('phone')->label('Telefon')->placeholder('–'),
TextColumn::make('city')->label('Ort')->placeholder('–'),
TextColumn::make('bookings_count')->label('Buchungen')->counts('bookings')->sortable(),
TextColumn::make('created_at')->label('Seit')->date('m/Y')->sortable(),
TextColumn::make('city')->label('Ort')->placeholder('–')->toggleable(),
TextColumn::make('tags')->label('Markierungen')->badge(),
TextColumn::make('bookings_count')->label('Aufenthalte')->counts($countedBookings)->sortable(),
TextColumn::make('bookings_sum_total')->label('Umsatz')->sum($countedBookings, 'total')->money('EUR', divideBy: 100, locale: 'de')->sortable(),
IconColumn::make('marketing_consent_at')->label('Angebote')->boolean()->getStateUsing(fn (Guest $record): bool => $record->marketing_consent_at !== null),
])
->filters([
Filter::make('returning')
->label('Stammgäste (ab 2 Aufenthalten)')
->query(fn (Builder $query): Builder => $query->has('bookings', '>=', 2)),
TernaryFilter::make('marketing_consent_at')
->label('Einwilligung Angebote')
->nullable(),
SelectFilter::make('tag')
->label('Markierung')
->options(fn (): array => Guest::query()->whereNotNull('tags')->pluck('tags')->flatten()->unique()->sort()->mapWithKeys(fn (string $tag): array => [$tag => $tag])->all())
->query(fn (Builder $query, array $data): Builder => $query->when($data['value'], fn (Builder $query, string $tag): Builder => $query->whereJsonContains('tags', $tag))),
TernaryFilter::make('anonymized_at')
->label('Anonymisierte anzeigen')
->nullable()
->default(false),
])
->recordActions([
EditAction::make(),
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Reviews\Pages;
use App\Filament\Resources\Reviews\ReviewResource;
use Filament\Resources\Pages\CreateRecord;
class CreateReview extends CreateRecord
{
protected static string $resource = ReviewResource::class;
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Reviews\Pages;
use App\Filament\Resources\Reviews\ReviewResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditReview extends EditRecord
{
protected static string $resource = ReviewResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Reviews\Pages;
use App\Filament\Resources\Reviews\ReviewResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListReviews extends ListRecords
{
protected static string $resource = ReviewResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
@@ -0,0 +1,70 @@
<?php
namespace App\Filament\Resources\Reviews;
use App\Enums\ReviewStatus;
use App\Filament\Resources\Reviews\Pages\CreateReview;
use App\Filament\Resources\Reviews\Pages\EditReview;
use App\Filament\Resources\Reviews\Pages\ListReviews;
use App\Filament\Resources\Reviews\Schemas\ReviewForm;
use App\Filament\Resources\Reviews\Tables\ReviewsTable;
use App\Models\Review;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use UnitEnum;
class ReviewResource extends Resource
{
protected static ?string $model = Review::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedStar;
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
protected static ?string $modelLabel = 'Bewertung';
protected static ?string $pluralModelLabel = 'Bewertungen';
protected static ?int $navigationSort = 3;
public static function getNavigationBadge(): ?string
{
$pending = Review::query()->where('status', ReviewStatus::Pending)->count();
return $pending > 0 ? (string) $pending : null;
}
public static function getNavigationBadgeColor(): string
{
return 'warning';
}
public static function form(Schema $schema): Schema
{
return ReviewForm::configure($schema);
}
public static function table(Table $table): Table
{
return ReviewsTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListReviews::route('/'),
'create' => CreateReview::route('/create'),
'edit' => EditReview::route('/{record}/edit'),
];
}
}
@@ -0,0 +1,67 @@
<?php
namespace App\Filament\Resources\Reviews\Schemas;
use App\Enums\ReviewStatus;
use App\Models\Property;
use App\Models\Review;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class ReviewForm
{
public static function configure(Schema $schema): Schema
{
$stars = [1 => '★', 2 => '★★', 3 => '★★★', 4 => '★★★★', 5 => '★★★★★'];
return $schema
->columns(3)
->components([
Section::make('Bewertung')
->columnSpan(2)
->columns(2)
->schema([
TextInput::make('display_name')->label('Angezeigter Name')->required()->maxLength(80),
DatePicker::make('stayed_on')->label('Aufenthalt'),
Select::make('rating')->label('Gesamt')->options($stars)->required(),
...collect(Review::CATEGORIES)->map(fn (string $label, string $field) => Select::make($field)->label($label)->options($stars))->values()->all(),
TextInput::make('title')->label('Überschrift')->maxLength(120)->columnSpanFull(),
Textarea::make('body')->label('Text')->rows(5)->columnSpanFull(),
Textarea::make('private_feedback')
->label('Nur für die Gastgeber')
->rows(3)
->disabled(fn (?Review $record): bool => $record?->source === 'website')
->columnSpanFull(),
]),
Section::make('Freigabe')
->columnSpan(1)
->schema([
Select::make('status')->label('Status')->options(ReviewStatus::class)->default(ReviewStatus::Approved)->required(),
Toggle::make('publish_consent')
->label('Gast hat Veröffentlichung erlaubt')
->disabled(fn (?Review $record): bool => $record?->source === 'website'),
TextInput::make('source')
->label('Quelle')
->helperText('„website“ = über den Bewertungslink. Bei übernommenen Bewertungen das Portal eintragen.')
->default('manuell')
->disabled(fn (?Review $record): bool => $record?->source === 'website')
->required(),
Select::make('property_id')
->label('Wohnung')
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
->default(fn (): ?int => Property::query()->value('id'))
->required(),
]),
Section::make('Öffentliche Antwort der Gastgeber')
->columnSpanFull()
->schema([
Textarea::make('response')->hiddenLabel()->rows(3)->placeholder('Optional – erscheint unter der Bewertung.'),
]),
]);
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Resources\Reviews\Tables;
use App\Enums\ReviewStatus;
use App\Models\Review;
use Filament\Actions\Action;
use Filament\Actions\EditAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class ReviewsTable
{
public static function configure(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
TextColumn::make('rating')
->label('Sterne')
->formatStateUsing(fn (int $state): string => str_repeat('★', $state).str_repeat('☆', 5 - $state))
->color('warning')
->sortable(),
TextColumn::make('display_name')
->label('Gast')
->description(fn (Review $record): ?string => $record->title)
->searchable(['display_name', 'title', 'body']),
TextColumn::make('status')->label('Status')->badge(),
IconColumn::make('publish_consent')->label('Darf veröffentlicht werden')->boolean(),
TextColumn::make('source')->label('Quelle'),
TextColumn::make('stayed_on')->label('Aufenthalt')->date('m/Y')->sortable(),
])
->filters([
SelectFilter::make('status')->label('Status')->options(ReviewStatus::class),
])
->recordActions([
Action::make('approve')
->label('Freigeben')
->icon(Heroicon::OutlinedCheck)
->color('success')
->visible(fn (Review $record): bool => $record->status !== ReviewStatus::Approved)
->action(fn (Review $record) => $record->update(['status' => ReviewStatus::Approved])),
Action::make('reject')
->label('Ablehnen')
->icon(Heroicon::OutlinedXMark)
->color('gray')
->visible(fn (Review $record): bool => $record->status === ReviewStatus::Pending)
->action(fn (Review $record) => $record->update(['status' => ReviewStatus::Rejected])),
EditAction::make(),
]);
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers;
use App\Models\Guest;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\URL;
/**
* Double opt-in confirmation and unsubscribe for offer e-mails. Both links are signed.
*/
class MarketingConsentController extends Controller
{
public function confirm(Guest $guest): View
{
if ($guest->marketing_consent_at === null) {
$guest->forceFill(['marketing_consent_at' => now()])->save();
}
return view('marketing-consent', [
'title' => 'Anmeldung bestätigt',
'message' => 'Vielen Dank! Wir informieren Sie künftig über freie Termine und Angebote. Sie können sich jederzeit wieder abmelden.',
'unsubscribeUrl' => URL::signedRoute('marketing.unsubscribe', $guest),
]);
}
public function unsubscribe(Guest $guest): View
{
$guest->forceFill(['marketing_consent_at' => null])->save();
return view('marketing-consent', [
'title' => 'Abgemeldet',
'message' => 'Sie erhalten keine Angebote mehr per E-Mail. Informationen zu Ihren Buchungen senden wir Ihnen selbstverständlich weiterhin.',
'unsubscribeUrl' => null,
]);
}
}
+8
View File
@@ -3,6 +3,7 @@
namespace App\Livewire;
use App\Actions\CreateReservation;
use App\Actions\RequestMarketingConsent;
use App\Availability\AvailabilityChecker;
use App\Exceptions\ReservationException;
use App\Models\Booking;
@@ -62,6 +63,9 @@ class BookingRequest extends Component
public bool $privacyAccepted = false;
/** Optional opt-in for offer e-mails (confirmed by double opt-in). */
public bool $marketingOptIn = false;
/** Honeypot, must stay empty. */
public string $website = '';
@@ -232,6 +236,10 @@ public function submit(CreateReservation $createReservation): void
return;
}
if ($this->marketingOptIn) {
rescue(fn () => app(RequestMarketingConsent::class)->handle($booking->guest));
}
$this->bookingId = $booking->id;
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Livewire;
use App\Actions\SubmitReview;
use App\Models\Booking;
use App\Models\Review;
use Illuminate\Contracts\View\View;
use Livewire\Component;
/**
* Review form for a finished stay, reached through the signed link in the review invitation.
*/
class ReviewForm extends Component
{
public Booking $booking;
public int $rating = 0;
/** @var array<string, int> */
public array $categories = ['rating_cleanliness' => 0, 'rating_equipment' => 0, 'rating_location' => 0, 'rating_host' => 0];
public string $title = '';
public string $body = '';
public string $privateFeedback = '';
public string $displayName = '';
public bool $publishConsent = true;
public bool $submitted = false;
public function mount(Booking $booking): void
{
$this->booking = $booking;
$this->displayName = $booking->guest->first_name.' '.mb_substr($booking->guest->last_name, 0, 1).'.'.($booking->guest->city ? ' aus '.$booking->guest->city : '');
}
public function submit(SubmitReview $submitReview): void
{
$this->validate([
'rating' => ['required', 'integer', 'between:1,5'],
'categories.*' => ['integer', 'between:0,5'],
'title' => ['nullable', 'string', 'max:120'],
'body' => ['nullable', 'string', 'max:3000'],
'privateFeedback' => ['nullable', 'string', 'max:3000'],
'displayName' => ['required', 'string', 'max:80'],
], [], ['rating' => 'Gesamtbewertung', 'displayName' => 'Angezeigter Name']);
$submitReview->handle($this->booking, [
'rating' => $this->rating,
...array_map(fn (int $value): ?int => $value > 0 ? $value : null, $this->categories),
'title' => $this->title ?: null,
'body' => $this->body ?: null,
'private_feedback' => $this->privateFeedback ?: null,
'display_name' => $this->displayName,
'publish_consent' => $this->publishConsent,
]);
$this->submitted = true;
}
public function render(): View
{
return view('livewire.review-form', [
'canReview' => $this->submitted || SubmitReview::canReview($this->booking),
'categoryLabels' => Review::CATEGORIES,
]);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Mail;
use App\Models\Guest;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\URL;
/**
* Double opt-in: the guest confirms that they want to receive offers.
*/
class MarketingConsentRequest extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Guest $guest) {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Bitte bestätigen: Angebote der Ferienwohnung Stommer',
replyTo: [new Address(config('fewo.owner.email'), config('fewo.owner.name'))],
);
}
public function content(): Content
{
return new Content(
with: ['url' => URL::temporarySignedRoute('marketing.confirm', now()->addDays(14), $this->guest)],
markdown: 'mail.marketing-consent-request',
);
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Mail;
use App\Models\Review;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
/**
* Notifies the landlord about a new review to approve.
*/
class NewReview extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Review $review) {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Neue Bewertung: '.str_repeat('★', $this->review->rating).' von '.$this->review->display_name,
);
}
public function content(): Content
{
return new Content(
markdown: 'mail.new-review',
);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Mail;
use App\Models\Booking;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\URL;
/**
* Asks the guest for a review a few days after departure.
*/
class ReviewRequest extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Booking $booking) {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Wie war Ihr Aufenthalt in Kühlungsborn?',
replyTo: [new Address(config('fewo.owner.email'), config('fewo.owner.name'))],
);
}
public function content(): Content
{
return new Content(
with: ['url' => URL::temporarySignedRoute('reviews.create', now()->addDays(90), $this->booking)],
markdown: 'mail.review-request',
);
}
}
+11
View File
@@ -11,6 +11,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* A reservation or booking. arrival is the first night, departure the day the guest leaves,
@@ -35,6 +36,7 @@
'internal_notes',
'confirmed_at',
'cancelled_at',
'review_requested_at',
])]
class Booking extends Model
{
@@ -65,6 +67,7 @@ protected function casts(): array
'hold_expires_at' => 'immutable_datetime',
'confirmed_at' => 'immutable_datetime',
'cancelled_at' => 'immutable_datetime',
'review_requested_at' => 'immutable_datetime',
];
}
@@ -112,6 +115,14 @@ protected function overlapping(Builder $query, CarbonInterface $from, CarbonInte
->whereDate('departure', '>', $from);
}
/**
* @return HasOne<Review, $this>
*/
public function review(): HasOne
{
return $this->hasOne(Review::class);
}
public function nights(): int
{
return (int) $this->arrival->diffInDays($this->departure);
+54 -1
View File
@@ -4,18 +4,35 @@
use Database\Factories\GuestFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
#[Fillable(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country', 'locale', 'notes'])]
#[Fillable(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country', 'locale', 'notes', 'tags'])]
class Guest extends Model
{
/** @use HasFactory<GuestFactory> */
use HasFactory, Notifiable;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'tags' => 'array',
'marketing_consent_at' => 'immutable_datetime',
'anonymized_at' => 'immutable_datetime',
];
}
/**
* @return HasMany<Booking, $this>
*/
@@ -31,4 +48,40 @@ protected function fullName(): Attribute
{
return Attribute::get(fn (): string => "{$this->first_name} {$this->last_name}");
}
/**
* Guests who confirmed (double opt-in) that they want to receive offers by e-mail.
*
* @param Builder<Guest> $query
* @return Builder<Guest>
*/
#[Scope]
protected function withMarketingConsent(Builder $query): Builder
{
return $query->whereNotNull('marketing_consent_at')->whereNull('anonymized_at');
}
/**
* Removes all personal data (GDPR). Bookings stay for accounting, without personal messages.
*/
public function anonymize(): void
{
DB::transaction(function (): void {
$this->bookings()->update(['message' => null]);
$this->forceFill([
'first_name' => 'Anonymisiert',
'last_name' => "#{$this->id}",
'email' => "anonymisiert-{$this->id}@invalid.local",
'phone' => null,
'street' => null,
'postal_code' => null,
'city' => null,
'notes' => null,
'tags' => null,
'marketing_consent_at' => null,
'anonymized_at' => now(),
])->save();
});
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
namespace App\Models;
use App\Enums\ReviewStatus;
use Database\Factories\ReviewFactory;
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;
/**
* A guest review. Reviews from the website always belong to a booking (verified stay);
* reviews taken over from portals carry their source instead.
*/
#[Fillable([
'property_id',
'booking_id',
'status',
'source',
'rating',
'rating_cleanliness',
'rating_equipment',
'rating_location',
'rating_host',
'title',
'body',
'private_feedback',
'display_name',
'publish_consent',
'stayed_on',
'response',
'responded_at',
'approved_at',
])]
class Review extends Model
{
/** @use HasFactory<ReviewFactory> */
use HasFactory;
/** Rating categories besides the overall rating, with their German labels. */
public const CATEGORIES = [
'rating_cleanliness' => 'Sauberkeit',
'rating_equipment' => 'Ausstattung',
'rating_location' => 'Lage',
'rating_host' => 'Gastgeber',
];
protected static function booted(): void
{
static::saving(function (Review $review): void {
if ($review->status === ReviewStatus::Approved && $review->approved_at === null) {
$review->approved_at = now();
}
if ($review->isDirty('response')) {
$review->responded_at = filled($review->response) ? now() : null;
}
});
}
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'status' => ReviewStatus::class,
'publish_consent' => 'boolean',
'stayed_on' => 'immutable_date',
'responded_at' => 'immutable_datetime',
'approved_at' => 'immutable_datetime',
];
}
/**
* @return BelongsTo<Property, $this>
*/
public function property(): BelongsTo
{
return $this->belongsTo(Property::class);
}
/**
* @return BelongsTo<Booking, $this>
*/
public function booking(): BelongsTo
{
return $this->belongsTo(Booking::class);
}
/**
* Reviews that may be shown on the website.
*
* @param Builder<Review> $query
* @return Builder<Review>
*/
#[Scope]
protected function published(Builder $query): Builder
{
return $query
->where('status', ReviewStatus::Approved)
->where('publish_consent', true)
->latest('stayed_on');
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Enums\UserRole;
class ReviewPolicy extends RolePolicy
{
protected function roles(): array
{
return [UserRole::Rentals, UserRole::Content];
}
}
+12
View File
@@ -34,4 +34,16 @@
*/
'deposit_due_days' => (int) env('FEWO_DEPOSIT_DUE_DAYS', 7),
/*
| Days after departure when guests are asked for a review.
*/
'review_request_after_days' => (int) env('FEWO_REVIEW_REQUEST_AFTER_DAYS', 2),
/*
| Years after the last stay after which guest data is anonymised automatically.
| Default 10 years because booking records are accounting documents (§ 147 AO);
| please confirm with your tax advisor.
*/
'guest_retention_years' => (int) env('FEWO_GUEST_RETENTION_YEARS', 10),
];
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Database\Factories;
use App\Enums\ReviewStatus;
use App\Models\Property;
use App\Models\Review;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Review>
*/
class ReviewFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'property_id' => Property::factory(),
'status' => ReviewStatus::Pending,
'source' => 'website',
'rating' => 5,
'body' => fake()->paragraph(),
'display_name' => fake()->firstName().' '.fake()->randomLetter().'.',
'publish_consent' => true,
'stayed_on' => fake()->dateTimeBetween('-1 year')->format('Y-m-d'),
];
}
}
@@ -0,0 +1,30 @@
<?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::table('guests', function (Blueprint $table) {
$table->json('tags')->nullable()->after('notes');
$table->dateTime('marketing_consent_at')->nullable()->after('tags');
$table->dateTime('anonymized_at')->nullable()->after('marketing_consent_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('guests', function (Blueprint $table) {
$table->dropColumn(['tags', 'marketing_consent_at', 'anonymized_at']);
});
}
};
@@ -0,0 +1,45 @@
<?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('reviews', function (Blueprint $table) {
$table->id();
$table->foreignId('property_id')->constrained()->cascadeOnDelete();
$table->foreignId('booking_id')->nullable()->unique()->constrained()->nullOnDelete();
$table->string('status')->index();
$table->string('source')->default('website');
$table->unsignedTinyInteger('rating');
$table->unsignedTinyInteger('rating_cleanliness')->nullable();
$table->unsignedTinyInteger('rating_equipment')->nullable();
$table->unsignedTinyInteger('rating_location')->nullable();
$table->unsignedTinyInteger('rating_host')->nullable();
$table->string('title')->nullable();
$table->text('body')->nullable();
$table->text('private_feedback')->nullable();
$table->string('display_name');
$table->boolean('publish_consent')->default(false);
$table->date('stayed_on')->nullable();
$table->text('response')->nullable();
$table->dateTime('responded_at')->nullable();
$table->dateTime('approved_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('reviews');
}
};
@@ -0,0 +1,28 @@
<?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::table('bookings', function (Blueprint $table) {
$table->dateTime('review_requested_at')->nullable()->after('cancelled_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('bookings', function (Blueprint $table) {
$table->dropColumn('review_requested_at');
});
}
};
+18
View File
@@ -57,6 +57,13 @@ ## 5. Verwaltungssystem (Admin)
- **Vorlagen:** E-Mail-Texte und Mietvertrag mit Platzhaltern editierbar.
- **Portale/Connectoren:** siehe Abschnitt 7.
## 5b. Rollen, Inhalte, Gäste, Customer Voice
- **Rollen:** Administrator (alles + Benutzer), Vermietung (Buchungen, Gäste, Preise, Angebote, Bewertungen), Inhalte (Bilder, Texte, Ausstattung, FAQ, Hinweise, Bewertungen).
- **Inhalte ohne CMS-Risiko:** feste Bausteine statt freier Seitenbau – Bilder (automatische WebP-Webgrößen, Sortierung per Drag & Drop), Webseiten-Texte (`config/content.php`), Ausstattung, FAQ, zeitgesteuerte Hinweis-Banner, Impressum/Datenschutz.
- **Gästeverzeichnis:** Kontaktdaten, Markierungen, Aufenthalte & Umsatz, Stammgast-Filter, CSV-Export, Werbe-Einwilligung per Double-Opt-in (Abmeldelink), Anonymisierung (manuell und automatisch nach Aufbewahrungsfrist, Standard 10 Jahre – mit Steuerberater abstimmen).
- **Customer Voice:** Einladung 2 Tage nach Abreise mit signiertem Link → Sterne (gesamt + Sauberkeit, Ausstattung, Lage, Gastgeber), Text, internes Feedback, Veröffentlichungs-Einwilligung → Freigabe im Admin, öffentliche Antwort möglich. Nur verifizierte Aufenthalte (§ 5b UWG-Hinweis auf der Webseite); Portalbewertungen manuell mit Quelle übernehmbar.
## 5a. Sonderangebote & Sonderkonditionen
Ein Angebot besteht aus einem **Vorteil** und beliebig vielen **Bedingungen** (leer = keine Einschränkung):
@@ -111,6 +118,17 @@ ## 7. Connector-/Plugin-System für Portale
- Jeder Sync wird protokolliert; Konflikte (Doppelbelegung) lösen eine sofortige Warn-Mail aus.
- Hinweis: iCal synchronisiert mit Verzögerung (Portale ziehen teils nur stündlich) – ein kleines Doppelbuchungsrisiko bleibt, wie bei allen Lösungen ohne Channel-Manager-API.
### 7a. Buchungshoheit & Architekturentscheidung
Anforderung: Geht auf einem Portal eine Buchung ein, muss der Zeitraum sofort überall (andere Portale + Webseite) gesperrt werden; Sync muss überwacht werden.
- **Unser System ist die zentrale Quelle der Belegung** („Single Source of Truth“): Import aller Portale → Sperrzeiten; Export eines iCal-Feeds je Portal mit *allen* Belegungen außer denen dieses Portals.
- **Grenze von iCal:** Wir können nur so schnell sperren, wie wir die Portale abfragen (bei uns alle 5 Min.) und wie oft die Portale unseren Feed abholen (portalabhängig, oft 30 Min. bis mehrere Stunden). Echtzeit gibt es nur über Portal-APIs – diese vergeben Booking.com, Airbnb und Vrbo/FeWo-direkt praktisch nur an zertifizierte Channel-Manager.
- **Stufe 1 (jetzt):** iCal-Connectoren + Überwachung in Laravel bei Strato. Webseiten-Anfragen sind risikofrei, weil wir vor jeder Bestätigung gegen alle importierten Belegungen prüfen.
- **Stufe 2 (falls Doppelbuchungen zwischen Portalen nicht tragbar sind):** Channel-Manager mit API und Webhooks als Portal-Hub (Kandidaten z. B. Smoobu, Beds24, Lodgify – Auswahl nach Portalabdeckung und Preis). Unser System bindet ihn als weiteren Connector an; Portalbuchungen kommen per Webhook in Sekunden.
- **Überwachung:** Sync-Protokoll je Kanal, Warnung bei fehlgeschlagenem oder veraltetem Abruf, sofortige Konflikt-Mail bei Überschneidungen, Status-Endpunkt `/health/sync` für externe Überwachung.
- **Eigener Server (n8n/FastAPI):** nicht als Kernbestandteil – ein zweites System würde Logik und Gästedaten aufteilen (Wartung, DSGVO). Sinnvoll als **unabhängiger Wächter**: n8n prüft `/health/sync` alle 5 Min. und alarmiert per Push/Telegram; optional Ersatz-Trigger für den Scheduler, falls der Strato-Cronjob ausfällt.
## 8. Rechtliches (Deutschland)
- Impressum, Datenschutzerklärung (DSGVO), Mietbedingungen/AGB – **Texte sollten juristisch geprüft werden**.
@@ -196,6 +196,11 @@ class="mt-1 w-full rounded-lg border-slate-300">
</label>
@error('privacyAccepted') <p class="mt-1 text-xs text-rose-700">{{ $message }}</p> @enderror
<label class="mt-3 flex items-start gap-2 text-sm text-slate-600">
<input type="checkbox" wire:model="marketingOptIn" class="mt-0.5 rounded border-slate-300">
<span>Ja, informieren Sie mich gelegentlich per E-Mail über freie Termine und Angebote (optional, jederzeit abbestellbar).</span>
</label>
<button type="submit"
@disabled(! $pricing['quote'])
wire:loading.attr="disabled"
@@ -0,0 +1,74 @@
<div class="mx-auto max-w-2xl">
@if ($submitted)
<div class="rounded-2xl border border-emerald-200 bg-emerald-50 p-8 text-center" role="status">
<h2 class="text-2xl font-semibold text-emerald-900">Herzlichen Dank!</h2>
<p class="mt-2 text-emerald-900">Ihre Bewertung ist bei uns angekommen. Wir freuen uns über jede Rückmeldung.</p>
</div>
@elseif (! $canReview)
<div class="rounded-2xl border border-slate-200 bg-white p-8 text-center">
<p class="text-slate-600">Für diesen Aufenthalt wurde bereits eine Bewertung abgegeben. Vielen Dank!</p>
</div>
@else
<form wire:submit="submit" class="space-y-6 rounded-2xl border border-slate-200 bg-white p-6 shadow-sm sm:p-8" novalidate>
<div>
<h2 class="text-xl font-semibold text-sea-900">Ihr Aufenthalt vom {{ $booking->arrival->format('d.m.') }} bis {{ $booking->departure->format('d.m.Y') }}</h2>
<p class="mt-1 text-sm text-slate-500">Bewertungen können nur von Gästen mit einer Buchung abgegeben werden.</p>
</div>
<fieldset>
<legend class="font-medium text-slate-800">Wie hat es Ihnen insgesamt gefallen? <span class="text-rose-600" aria-hidden="true">*</span></legend>
<div class="mt-2 flex gap-1" role="radiogroup" aria-label="Gesamtbewertung">
@for ($star = 1; $star <= 5; $star++)
<button type="button" wire:click="$set('rating', {{ $star }})" role="radio" aria-checked="{{ $rating === $star ? 'true' : 'false' }}" aria-label="{{ $star }} von 5 Sternen"
@class(['text-4xl leading-none transition', 'text-amber-500' => $star <= $rating, 'text-slate-300 hover:text-amber-300' => $star > $rating])>★</button>
@endfor
</div>
@error('rating') <p class="mt-1 text-sm text-rose-700">{{ $message }}</p> @enderror
</fieldset>
<div class="grid gap-4 sm:grid-cols-2">
@foreach ($categoryLabels as $field => $label)
<fieldset wire:key="category-{{ $field }}">
<legend class="text-sm text-slate-700">{{ $label }}</legend>
<div class="mt-1 flex gap-1">
@for ($star = 1; $star <= 5; $star++)
<button type="button" wire:click="$set('categories.{{ $field }}', {{ $star }})" aria-label="{{ $label }}: {{ $star }} von 5"
@class(['text-2xl leading-none', 'text-amber-500' => $star <= $categories[$field], 'text-slate-300 hover:text-amber-300' => $star > $categories[$field]])>★</button>
@endfor
</div>
</fieldset>
@endforeach
</div>
<label class="block text-sm">
<span class="font-medium text-slate-700">Überschrift</span>
<input type="text" wire:model="title" maxlength="120" class="mt-1 w-full rounded-lg border-slate-300" placeholder="z. B. Ruhig, gemütlich, perfekt gelegen">
</label>
<label class="block text-sm">
<span class="font-medium text-slate-700">Ihre Erfahrung</span>
<textarea wire:model="body" rows="5" class="mt-1 w-full rounded-lg border-slate-300"></textarea>
</label>
<label class="block text-sm">
<span class="font-medium text-slate-700">Nur für die Gastgeber (wird nicht veröffentlicht)</span>
<textarea wire:model="privateFeedback" rows="3" class="mt-1 w-full rounded-lg border-slate-300" placeholder="Was können wir verbessern?"></textarea>
</label>
<label class="block text-sm">
<span class="font-medium text-slate-700">So soll Ihr Name erscheinen <span class="text-rose-600" aria-hidden="true">*</span></span>
<input type="text" wire:model="displayName" maxlength="80" class="mt-1 w-full rounded-lg border-slate-300">
@error('displayName') <span class="mt-1 block text-xs text-rose-700">{{ $message }}</span> @enderror
</label>
<label class="flex items-start gap-2 text-sm">
<input type="checkbox" wire:model="publishConsent" class="mt-0.5">
<span>Meine Bewertung darf mit dem angegebenen Namen auf der Webseite veröffentlicht werden.</span>
</label>
<button type="submit" wire:loading.attr="disabled" class="w-full rounded-xl bg-sea-700 px-4 py-3 font-semibold text-white hover:bg-sea-800 disabled:opacity-50">
Bewertung absenden
</button>
</form>
@endif
</div>
@@ -0,0 +1,16 @@
<x-mail::message>
# Bitte bestätigen Sie Ihre Anmeldung
Guten Tag {{ $guest->full_name }},
Sie möchten von uns gelegentlich über freie Termine und Angebote unserer Ferienwohnung in Kühlungsborn informiert werden. Bitte bestätigen Sie das mit einem Klick:
<x-mail::button :url="$url">
Ja, ich möchte Angebote erhalten
</x-mail::button>
Wenn Sie das nicht angefordert haben, ignorieren Sie diese E-Mail einfach – Sie erhalten dann keine weiteren Nachrichten. Eine erteilte Einwilligung können Sie jederzeit widerrufen.
Herzliche Grüße<br>
{{ config('fewo.owner.name') }}
</x-mail::message>
+23
View File
@@ -0,0 +1,23 @@
<x-mail::message>
# Neue Bewertung
**{{ $review->display_name }}** hat {{ $review->rating }} von 5 Sternen vergeben.
@if ($review->title)
**{{ $review->title }}**
@endif
{{ $review->body }}
@if ($review->private_feedback)
<x-mail::panel>
**Nur für Sie:** {{ $review->private_feedback }}
</x-mail::panel>
@endif
Veröffentlichung erlaubt: {{ $review->publish_consent ? 'ja' : 'nein' }}
<x-mail::button :url="\App\Filament\Resources\Reviews\ReviewResource::getUrl('edit', ['record' => $review])">
Bewertung prüfen
</x-mail::button>
</x-mail::message>
@@ -0,0 +1,16 @@
<x-mail::message>
# Wie war Ihr Aufenthalt?
Guten Tag {{ $booking->guest->full_name }},
wir hoffen, Sie hatten eine schöne Zeit in unserer Ferienwohnung in Kühlungsborn und sind gut nach Hause gekommen.
Wir würden uns sehr freuen, wenn Sie sich zwei Minuten Zeit nehmen und uns erzählen, wie es Ihnen gefallen hat. Ihre Bewertung hilft anderen Gästen – und uns, noch besser zu werden.
<x-mail::button :url="$url">
Jetzt bewerten
</x-mail::button>
Herzliche Grüße<br>
{{ config('fewo.owner.name') }}
</x-mail::message>
@@ -0,0 +1,9 @@
<x-layouts.site :title="$title">
<div class="mx-auto max-w-xl rounded-2xl border border-slate-200 bg-white p-8 text-center shadow-sm">
<h1 class="text-2xl font-semibold text-sea-900">{{ $title }}</h1>
<p class="mt-3 text-slate-600">{{ $message }}</p>
@if ($unsubscribeUrl)
<p class="mt-6 text-sm text-slate-500"><a href="{{ $unsubscribeUrl }}" class="underline">Doch nicht? Hier abmelden.</a></p>
@endif
</div>
</x-layouts.site>
+8
View File
@@ -0,0 +1,8 @@
<x-layouts.site title="Ihre Bewertung">
<h1 class="text-center text-3xl font-semibold tracking-tight text-sea-900">Wie war Ihr Aufenthalt?</h1>
<p class="mx-auto mt-2 max-w-xl text-center text-slate-600">Vielen Dank, dass Sie sich einen Moment Zeit nehmen.</p>
<div class="mt-8">
<livewire:review-form :booking="$booking" />
</div>
</x-layouts.site>
+12
View File
@@ -1,5 +1,17 @@
<?php
use App\Actions\AnonymizeGuests;
use App\Actions\RequestReviews;
use Illuminate\Support\Facades\Schedule;
Schedule::command('bookings:expire-holds')->everyFiveMinutes()->withoutOverlapping();
Schedule::call(fn (RequestReviews $requestReviews) => $requestReviews->handle())
->name('reviews:request')
->dailyAt('10:00')
->withoutOverlapping();
Schedule::call(fn (AnonymizeGuests $anonymizeGuests) => $anonymizeGuests->handle())
->name('guests:anonymize')
->monthlyOn(1, '03:00')
->withoutOverlapping();
+8
View File
@@ -1,5 +1,7 @@
<?php
use App\Http\Controllers\MarketingConsentController;
use App\Models\Booking;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
@@ -7,3 +9,9 @@
});
Route::view('/buchen', 'booking')->name('booking.create');
Route::middleware('signed')->group(function () {
Route::get('/bewertung/{booking}', fn (Booking $booking) => view('review', ['booking' => $booking]))->name('reviews.create');
Route::get('/angebote/bestaetigen/{guest}', [MarketingConsentController::class, 'confirm'])->name('marketing.confirm');
Route::get('/angebote/abmelden/{guest}', [MarketingConsentController::class, 'unsubscribe'])->name('marketing.unsubscribe');
});
+168
View File
@@ -0,0 +1,168 @@
<?php
namespace Tests\Feature;
use App\Actions\AnonymizeGuests;
use App\Actions\RequestReviews;
use App\Enums\BookingStatus;
use App\Enums\ReviewStatus;
use App\Enums\UserRole;
use App\Filament\Resources\Guests\GuestResource;
use App\Filament\Resources\Guests\Pages\EditGuest;
use App\Filament\Resources\Guests\Pages\ListGuests;
use App\Filament\Resources\Reviews\Pages\ListReviews;
use App\Filament\Resources\Reviews\ReviewResource;
use App\Livewire\BookingRequest;
use App\Livewire\ReviewForm;
use App\Mail\MarketingConsentRequest;
use App\Mail\NewReview;
use App\Mail\ReviewRequest;
use App\Models\Booking;
use App\Models\Guest;
use App\Models\Property;
use App\Models\Review;
use App\Models\User;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\URL;
use Livewire\Livewire;
use Tests\TestCase;
class GuestRelationsTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed(PropertySeeder::class);
$this->property = Property::sole();
Mail::fake();
}
public function test_review_invitation_is_sent_once_after_departure(): void
{
$due = $this->stay('2026-10-13', '2026-10-20');
$this->stay('2026-10-15', '2026-10-21');
$this->stay('2026-08-01', '2026-08-08');
Booking::factory()->for($this->property)->create(['status' => BookingStatus::Cancelled, 'arrival' => '2026-10-10', 'departure' => '2026-10-17']);
$this->assertSame(1, (new RequestReviews)->handle());
$this->assertSame(0, (new RequestReviews)->handle());
Mail::assertSent(ReviewRequest::class, fn (ReviewRequest $mail): bool => $mail->hasTo($due->guest->email));
$this->assertNotNull($due->fresh()->review_requested_at);
}
public function test_guest_submits_a_review_through_the_signed_link(): void
{
$booking = $this->stay('2026-10-13', '2026-10-20');
$url = URL::temporarySignedRoute('reviews.create', now()->addDays(90), $booking);
$this->withoutVite()->get($url)->assertOk()->assertSeeLivewire(ReviewForm::class);
$this->withoutVite()->get(route('reviews.create', $booking))->assertForbidden();
Livewire::test(ReviewForm::class, ['booking' => $booking])
->set('rating', 5)
->set('categories.rating_cleanliness', 4)
->set('body', 'Wunderbar ruhig, wir kommen wieder.')
->set('privateFeedback', 'Der Toaster ist alt.')
->call('submit')
->assertSee('Herzlichen Dank');
$review = Review::sole();
$this->assertSame([ReviewStatus::Pending, 5, 4, 'website'], [$review->status, $review->rating, $review->rating_cleanliness, $review->source]);
$this->assertSame(0, Review::published()->count());
Mail::assertSent(NewReview::class);
Livewire::test(ReviewForm::class, ['booking' => $booking])->assertSee('bereits eine Bewertung');
}
public function test_approved_reviews_with_consent_are_published(): void
{
$this->actingAs(User::factory()->role(UserRole::Content)->create());
$review = Review::factory()->for($this->property)->create();
Review::factory()->for($this->property)->create(['publish_consent' => false, 'status' => ReviewStatus::Approved]);
$this->get(ReviewResource::getUrl('index'))->assertOk();
Livewire::test(ListReviews::class)->callTableAction('approve', $review);
$this->assertNotNull($review->fresh()->approved_at);
$this->assertSame([$review->id], Review::published()->pluck('id')->all());
}
public function test_marketing_opt_in_is_confirmed_by_double_opt_in(): void
{
Livewire::test(BookingRequest::class)
->set('arrival', '2026-11-07')
->set('departure', '2026-11-10')
->set('firstName', 'Anna')
->set('lastName', 'Muster')
->set('email', 'anna@example.com')
->set('privacyAccepted', true)
->set('marketingOptIn', true)
->call('submit');
$guest = Guest::sole();
$this->assertNull($guest->marketing_consent_at);
Mail::assertSent(MarketingConsentRequest::class);
$this->withoutVite()->get(URL::temporarySignedRoute('marketing.confirm', now()->addDay(), $guest))->assertOk()->assertSee('Anmeldung bestätigt');
$this->assertNotNull($guest->fresh()->marketing_consent_at);
$this->withoutVite()->get(URL::signedRoute('marketing.unsubscribe', $guest))->assertOk();
$this->assertNull($guest->fresh()->marketing_consent_at);
}
public function test_guests_are_anonymized_after_the_retention_period(): void
{
$old = $this->stay('2015-07-01', '2015-07-08')->guest;
$old->forceFill(['created_at' => '2015-06-01'])->save();
$recent = $this->stay('2026-07-01', '2026-07-08')->guest;
$this->assertSame(1, (new AnonymizeGuests)->handle());
$old->refresh();
$this->assertNotNull($old->anonymized_at);
$this->assertSame('Anonymisiert', $old->first_name);
$this->assertNull($old->phone);
$this->assertNull($recent->fresh()->anonymized_at);
$this->assertSame(1, $old->bookings()->count());
}
public function test_admin_sees_guest_history_and_can_export_and_anonymize(): void
{
$this->actingAs(User::factory()->create());
$guest = $this->stay('2026-07-01', '2026-07-08')->guest;
$guest->update(['tags' => ['Stammgast']]);
$this->get(GuestResource::getUrl('edit', ['record' => $guest]))->assertOk();
Livewire::test(ListGuests::class)->callAction('export', ['consent_only' => false])->assertFileDownloaded('gaeste-2026-10-22.csv');
Livewire::test(EditGuest::class, ['record' => $guest->getRouteKey()])->callAction('anonymize');
$this->assertNotNull($guest->fresh()->anonymized_at);
}
public function test_rentals_role_cannot_anonymize(): void
{
$this->actingAs(User::factory()->role(UserRole::Rentals)->create());
$guest = $this->stay('2026-07-01', '2026-07-08')->guest;
Livewire::test(EditGuest::class, ['record' => $guest->getRouteKey()])->assertActionHidden('anonymize');
}
private function stay(string $arrival, string $departure): Booking
{
return Booking::factory()->for($this->property)->create([
'status' => BookingStatus::Paid,
'arrival' => $arrival,
'departure' => $departure,
]);
}
}