مهدی
2 سال پیش توسط مهدی مطرح شد
1 پاسخ

عدم ارسال دیتا در پوش نوتیفیکیشن

با سلام.من برای ارسال پوش نوتیفیکیشن در لاراول از پکیج زیر استفاده کردم
لینک پکیج
زمانی که نوتیفیکیشن را پوش میکنم نوتیفیکیشن پوش میشود ولی به جای اطلاعات بنده یک نوتیفیکیشن با متن
this site has been updated in background
برای کاربر نمایش داده میشود،در فایل sw.js از دیتا که لاگ گرفتم مقدار null برمیگرداند و حدسم اینه که مشکل از سرور است در زیر کدهای سرور رو هم میزارم

کنترلر ابتدایی

 public function test(Request $request)
    {  
        $user = User::find(2);
        $user->notify(new HelloNotification);
    {

کلاس HelloNotification

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Carbon;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;

class HelloNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database', 'broadcast', WebPushChannel::class];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'title' => 'Hello from Laravel!',
            'body' => 'Thank you for using our application.',
            'action_url' => 'https://laravel.com',
            'created' => Carbon::now()->toIso8601String(),
        ];
    }

    /**
     * Get the web push representation of the notification.
     *
     * @param  mixed  $notifiable
     * @param  mixed  $notification
     * @return \Illuminate\Notifications\Messages\DatabaseMessage
     */
    public function toWebPush($notifiable, $notification)
    {
        return (new WebPushMessage)
            ->title('Hello from Laravel!')
            ->icon('/notification-icon.png')
            ->body('Thank you for using our application.')
            ->action('View app', 'view_app')
            ->data(['id' => $notification->id]);
    }
}

ثبت پرسش جدید
مهدی
تخصص : برنامه نویس
@mahdiam200 2 سال پیش مطرح شد
0

کسی با این پکیج کار نکرده؟


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام