fix: mail preview endpoint not loading and crashing on null data
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>
This commit is contained in:
@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
|
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
|
web: __DIR__.'/../routes/web.php',
|
||||||
api: __DIR__.'/../routes/api.php',
|
api: __DIR__.'/../routes/api.php',
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
|
|||||||
@@ -5,23 +5,49 @@ use App\Mail\RegistrationApprovedMail;
|
|||||||
use App\Mail\RegistrationConfirmationMail;
|
use App\Mail\RegistrationConfirmationMail;
|
||||||
use App\Mail\RegistrationRejectedMail;
|
use App\Mail\RegistrationRejectedMail;
|
||||||
use App\Models\Event;
|
use App\Models\Event;
|
||||||
use App\Models\Organisation;
|
|
||||||
use App\Models\Person;
|
use App\Models\Person;
|
||||||
use App\Models\UserInvitation;
|
use App\Models\UserInvitation;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
if (app()->environment('local', 'staging')) {
|
if (app()->environment('local', 'staging')) {
|
||||||
Route::get('/mail-preview/{type}', function (string $type) {
|
Route::get('/mail-preview/{type}', function (string $type) {
|
||||||
$org = Organisation::first();
|
$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();
|
$event = Event::first();
|
||||||
$person = Person::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) {
|
return match ($type) {
|
||||||
'registration-confirmation' => new RegistrationConfirmationMail($person, $event),
|
'registration-confirmation' => new RegistrationConfirmationMail($person, $event),
|
||||||
'registration-approved' => new RegistrationApprovedMail($person, $event),
|
'registration-approved' => new RegistrationApprovedMail($person, $event),
|
||||||
'registration-rejected' => new RegistrationRejectedMail($person, $event, 'Helaas geen plek meer.'),
|
'registration-rejected' => new RegistrationRejectedMail($person, $event, 'Helaas geen plek meer.'),
|
||||||
'invitation' => new InvitationMail(UserInvitation::first()),
|
|
||||||
default => abort(404),
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user