53 lines
1.6 KiB
PHP

@php
$toasts = [];
// 컨트롤러에서 with('toast', [...])로 보낸 경우
if (session()->has('toast')) {
$t = session('toast');
if (is_array($t)) $toasts[] = $t;
}
// 라라벨 기본 status/error도 같이 지원
if (session()->has('status')) {
$toasts[] = ['type' => 'success', 'title' => '안내', 'message' => (string) session('status')];
}
if (session()->has('error')) {
$toasts[] = ['type' => 'danger', 'title' => '오류', 'message' => (string) session('error')];
}
// validation 에러도 토스트로 합치기(여러 줄)
if ($errors->any()) {
$toasts[] = [
'type' => 'danger',
'title' => '입력 오류',
'message' => implode("\n", $errors->all()),
];
}
@endphp
@if(!empty($toasts))
<div class="a-toast-wrap" id="aToastWrap">
@foreach($toasts as $t)
@php
$type = $t['type'] ?? 'info'; // success|danger|warn|info
$title = $t['title'] ?? '알림';
$msg = $t['message'] ?? '';
@endphp
<div class="a-toast a-toast--{{ $type }}">
<div class="a-toast__title">{{ $title }}</div>
<div class="a-toast__msg">{!! nl2br(e((string)$msg)) !!}</div>
</div>
@endforeach
</div>
<script>
(function(){
const wrap = document.getElementById('aToastWrap');
if(!wrap) return;
setTimeout(() => {
wrap.querySelectorAll('.a-toast').forEach(el => el.remove());
}, 3500);
})();
</script>
@endif