Laravel notification with livewire

Hello folks, I'm stuck with laravel notification. It's not related to the filament. But I'm using filament for this project. In the laravel community, no one helps out yet btw. The things I'm trying to send notifications when a user comments on posts. In the database notifications data is there but I can't fetch the data that give me null or empty. I'm not using a queue. Hope you guys help me. I was stucking the whole day. Thank you.
$users->unreadNotifications;
= Illuminate\Notifications\DatabaseNotificationCollection {#5579
all: [],
}
$users->unreadNotifications;
= Illuminate\Notifications\DatabaseNotificationCollection {#5579
all: [],
}
<?php

namespace App\Notifications;

use App\Models\Comment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class NotifyWhenComment extends Notification
{
use Queueable;

/**
* Create a new notification instance.
*/
public function __construct(public Comment $comment)
{
//
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'comment_id' => $this->comment->id,
'comment_content' => $this->comment->content,
'user_avatar' => $this->comment->user->profile_photo_url,
'user_name' => $this->comment->user->name,
'feeling_id' => $this->comment->feeling->id,
'feeling_slug' => $this->comment->feeling->slug,
'feeling_title' => $this->comment->feeling->title,
];
}
}
<?php

namespace App\Notifications;

use App\Models\Comment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class NotifyWhenComment extends Notification
{
use Queueable;

/**
* Create a new notification instance.
*/
public function __construct(public Comment $comment)
{
//
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'comment_id' => $this->comment->id,
'comment_content' => $this->comment->content,
'user_avatar' => $this->comment->user->profile_photo_url,
'user_name' => $this->comment->user->name,
'feeling_id' => $this->comment->feeling->id,
'feeling_slug' => $this->comment->feeling->slug,
'feeling_title' => $this->comment->feeling->title,
];
}
}
11 Replies
wyChoong
wyChoong2y ago
it looks like your notification is tie to your Comment model but you looking thru User model check what is your notifiable_type and notifiable_id value
Shaung Bhone
Shaung BhoneOP2y ago
here
wyChoong
wyChoong2y ago
check what queries run when trying to retrieve unread notification
Shaung Bhone
Shaung BhoneOP2y ago
[] empty
Shaung Bhone
Shaung BhoneOP2y ago
@wychoong here
wyChoong
wyChoong2y ago
your previous screenshot show that notifiable_id is 12, but you looking notification for User id 1?
Shaung Bhone
Shaung BhoneOP2y ago
sry here
Shaung Bhone
Shaung BhoneOP2y ago
wyChoong
wyChoong2y ago
so you can actually get the notification, no?
Shaung Bhone
Shaung BhoneOP2y ago
Actually, I want to get all notifications when auth user comments on other posts. Ops, I see. thank you I got it. My false. I'm thinking wrong logic. Thank you so. Damn. Need to rest. zzz Thank you so much.
wyChoong
wyChoong2y ago
👍
Want results from more Discord servers?
Add your server