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

+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];
}
}