Betmen35 Sorunuzun yanıtı sanırım şu:
routes/api.php
Route::get('notifications', [NotificationController::class, 'index']);
app/Http/Controllers/NotificationController.php
public function index(Requets $request)
{
$notifications = Notification::take($request->input('take', 5))
->latest()
->get();
return view('notifications', compact('notifications'));
}
resources/views/notifications.blade.php
@if($notifications)
<ul>
@foreach($notifications as $notification)
<li>
<p>{{ $notification->title }}</p>
<small>{{ $notification->created_at->diffForHumans() }}</small>
<li>
@endcoreach
</ul>
@else
<p>Gösterilecek bildirim yok</p>
@endif
Göstermek istediğiniz sayfada
<div id="notifications">
Yükleniyor...
</div>
<script>
const take = 5
setInterval(function(){
$("#notifications").load("/api/notifications?take=" + take);
}, 2000);
</script>
Artık 2 saniyede bir en son gelen 5 bildirimi notifications divi içinde ul listesi şeklinde gösterecek:
<div id="notifications">
<ul>
<li>
<p>Bu en son gelen bildirim</p>
<small>2 saniye önce</small>
<li>
<li>
<p>3 kullanıcının adres bilgileri eksik!</p>
<small>5 dakika önce</small>
<li>
<li>
<p>Veritabanı yedeklemesi tamamlandı.</p>
<small>1 saat önce</small>
<li>
...
</ul>
</div>