Notifications at friends don't see in view balde

37 Views Asked by At

I have a problem to view the notifications for each user.

After I have saved my new member, I want to send a notification for all user's friends. So:

$member->save();

    $user = auth()->user();
   $user_id=$user->id;
   
    $followers=Friend::where('user_id',$user_id)->get();
    Notification::send($followers, new Notifiche($member->name));
    $notifications = [];
    foreach ($followers as $follower) {
    $notifications[] = $follower->notifications;
    }
return redirect('/home')->with('notifications',$notifications);
} 

In the view :

@if(!empty($notifications))
  @foreach ($notifications as $notification)
    <p>{{$notification->data['name']}}</p>
  @endforeach 
@else
<a>+aaa</a>
@endif

I don't know the problem, because in the database the information has been saved. Notifiable type in database this case is App/Model/Friend. Then, I try to change follower to auth()->user() and it does work.

@if(!empty(auth()->user()->notifications))
@foreach (auth()->user()->notifications as $notification)
<p>{{$notification->data['name']}}</p>
 @endforeach 
@else
<a>+0</a>
@endif

and in the controller:

$users = auth()->user();
    $user_id=$user->id;
    Notification::send($users, new Notifiche($member->name));        
return redirect('/home')->with('notifications',$users->notifications);
} 

In this case the notifiable type is App/Model/User so I can see the relative notifications in the view. So I don't know how to proceed. Any idea?

0

There are 0 best solutions below