Register web.php in bootstrap/app.php (was missing, so the route was never loaded). Add null checks for all model queries with helpful error messages instead of TypeErrors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Mail\InvitationMail;
|
|
use App\Mail\RegistrationApprovedMail;
|
|
use App\Mail\RegistrationConfirmationMail;
|
|
use App\Mail\RegistrationRejectedMail;
|
|
use App\Models\Event;
|
|
use App\Models\Person;
|
|
use App\Models\UserInvitation;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
if (app()->environment('local', 'staging')) {
|
|
Route::get('/mail-preview/{type}', function (string $type) {
|
|
$supportedTypes = [
|
|
'registration-confirmation',
|
|
'registration-approved',
|
|
'registration-rejected',
|
|
'invitation',
|
|
];
|
|
|
|
if (! in_array($type, $supportedTypes)) {
|
|
abort(404, "Unknown mail type '{$type}'. Supported types: " . implode(', ', $supportedTypes));
|
|
}
|
|
|
|
if ($type === 'invitation') {
|
|
$invitation = UserInvitation::first();
|
|
|
|
if (! $invitation) {
|
|
return response('No UserInvitation found in the database. Create one first to preview this mail.', 422);
|
|
}
|
|
|
|
return new InvitationMail($invitation);
|
|
}
|
|
|
|
$event = Event::first();
|
|
$person = Person::first();
|
|
|
|
if (! $event || ! $person) {
|
|
$missing = collect([
|
|
'Event' => $event,
|
|
'Person' => $person,
|
|
])->filter(fn ($v) => $v === null)->keys()->implode(', ');
|
|
|
|
return response("No test data found. Missing: {$missing}. Seed the database first.", 422);
|
|
}
|
|
|
|
return match ($type) {
|
|
'registration-confirmation' => new RegistrationConfirmationMail($person, $event),
|
|
'registration-approved' => new RegistrationApprovedMail($person, $event),
|
|
'registration-rejected' => new RegistrationRejectedMail($person, $event, 'Helaas geen plek meer.'),
|
|
};
|
|
});
|
|
}
|