Notification not working
hello, notification is not working well, while mail sending and notification stored in database, but not display in bell icon
2 Replies
I used database notification in Panel also, here is my code <?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\PriceRequest;
class AdminReplyNotification extends Notification
{
use Queueable;
protected ?PriceRequest $priceRequest = null;
public function __construct(PriceRequest $priceRequest) { $this->priceRequest = $priceRequest; } / * Get the notification's delivery channels. * * @return array<int, string> */ public function via(object $notifiable): array { return ['database', 'mail']; } / * Get the mail representation of the notification. */public function toDatabase($notifiable) { return [ 'title' => 'Admin replied', 'message' => 'Admin replied on your ' .$this->priceRequest->publication->name . ' query.', ]; } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->subject('Admin Reply to Your Request') ->line('You have received a reply to your request.') ->action('View Reply', url('/user/price-requests/'.$this->priceRequest->id)) ->line('Thank you from TS Newswire!'); } /** * Get the array representation of the notification. * * @return array<string, mixed> */ public function toArray(object $notifiable): array { return [ // ]; } } calling this notification here " if ($record->user) { $record->user->notify(new AdminReplyNotification($record)); } " while tinker show the notification
public function __construct(PriceRequest $priceRequest) { $this->priceRequest = $priceRequest; } / * Get the notification's delivery channels. * * @return array<int, string> */ public function via(object $notifiable): array { return ['database', 'mail']; } / * Get the mail representation of the notification. */public function toDatabase($notifiable) { return [ 'title' => 'Admin replied', 'message' => 'Admin replied on your ' .$this->priceRequest->publication->name . ' query.', ]; } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->subject('Admin Reply to Your Request') ->line('You have received a reply to your request.') ->action('View Reply', url('/user/price-requests/'.$this->priceRequest->id)) ->line('Thank you from TS Newswire!'); } /** * Get the array representation of the notification. * * @return array<string, mixed> */ public function toArray(object $notifiable): array { return [ // ]; } } calling this notification here " if ($record->user) { $record->user->notify(new AdminReplyNotification($record)); } " while tinker show the notification
Please read #✅┊rules and format your code properly!