@php // Collect possible flash toasts (your original code — keep as-is) $toasts = []; $map = [ 'success' => 'Success', 'error' => 'Error', 'warning' => 'Warning', 'info' => 'Info', ]; foreach ($map as $key => $title) { if (session()->has($key)) { $payload = session($key); $message = is_bool($payload) ? null : $payload; $toasts[] = [ 'type' => $key, 'title' => $title, 'message' => $message, ]; } } if ($errors && $errors->any()) { $toasts[] = [ 'type' => 'error', 'title' => 'Validation failed', 'message' => $errors->all(), ]; } if (session()->has('toast')) { $t = session('toast'); $toasts[] = [ 'type' => $t['type'] ?? 'info', 'title' => ucfirst($t['type'] ?? 'Info'), 'message' => $t['message'] ?? null, ]; } @endphp @if(count($toasts))
@foreach($toasts as $i => $t) @php $hasMessage = !empty($t['message']); $autohide = $hasMessage && !is_array($t['message']) ? 'true' : 'false'; $bgClass = in_array($t['type'], ['success','info','warning']) ? 'bg-success' : 'bg-danger'; $defaultText = $t['type'] === 'success' ? 'Operation completed successfully.' : 'Something went wrong.'; @endphp @endforeach
@push('scripts') @endpush @endif