@php
// Convert legacy session success and validation errors into the unified
// `notifications` shape for the current request only. Use session()->now
// so we don't re-flash for the next request and risk persistence.
$currentNotifications = session('notifications', []);
if (session('success')) {
$currentNotifications[] = [
'type' => 'success',
'message' => session('success'),
'options' => ['title' => 'Success!', 'duration' => 5000],
];
}
if ($errors->any()) {
foreach ($errors->all() as $error) {
$currentNotifications[] = [
'type' => 'error',
'message' => $error,
'options' => ['title' => 'Validation Error', 'duration' => 8000],
];
}
}
if (!empty($currentNotifications)) {
// Make available for the current render only
session()->now('notifications', $currentNotifications);
}
@endphp