I'm trying to show a user's notifications with the following code:
@foreach(Auth::user()->notifications as $notification)
<li class="notification-item">
@include ('notifications.' . kebab_case(class_basename($notification->type)))
</li>
@endforeach
Using polymorphism the code includes multiple notification templates like the following:
@extends('notifications.template')
@section('notification-link', '#')
@section('notification-title', 'Testing Title')
@section('notification-picture', 'Some hardcored picture')
@section('notification-time', $notification->created_at->diffForHumans())
@section('notification-text')
@endsection
Which at the same time is extending a simple notification template:
notifications/template.blade.php
<a href="@yield('notification-link')">
<img class="notification-picture" src="@yield('notification-picture')">
<span class="notification-content">
<span class="notification-title">
@yield('notification-title')
</span>
<span class="notification-text">
@yield('notification-text')
</span>
<span class="notification-time">
@yield('notification-time')
</span>
</span>
</a>
For some reason I can't understand, when there's more than two notifications weird things happen. All notification contain the information from the most recent one. Why is this happening?
For example:
If I have at first one notification "Please confirm your email". I get the following:
- Please confirm your email
But if I now get a second notification "Email confirmed!", the notification list appears like the following:
- Email confirmed!
- Email confirmed!
However, both the notifications appear in the Auth::user()->notifications collection.
via Flerex