2

I have installed https://github.com/laravel-notification-channels/webpush in my project but when send notifications there are nothing. It doesnt work This is laravel notifications documentation: https://laravel.com/docs/5.5/notifications

This is my code - I have created a notification:

class AccountApproved extends Notification {
use Queueable;

public function __construct()
{
    //
}

public function via($notifiable)
{
    return [WebPushChannel::class];
}

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()
    ];
}

public function toWebPush($notifiable, $notification)
{
    return WebPushMessage::create()
        ->title('Hello from Laravel!')
        ->icon('/notification-icon.png')
        ->body('Thank you for using our application.')
        ->action('View app', 'view_app');
}}

and I call Notification in my controller:

     $when = Carbon::now();

    $request->user()->notify((new AccountApproved)->delay($when));

But I Webpush doesnt work. What's wrong?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
kouakou alexy
  • 151
  • 2
  • 12

2 Answers2

1

Make sure you are running queue worker like this:

php artisan queue:work

in command line. Otherwise queued notification won't be sent.

In case it doesn't help look at your error log and verify if there are any errors in there

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • it's weird, php artisan queue:work can't work. After several minutes of waiting, the console is still frozen. I'll get the solution on Google and I come back – kouakou alexy Oct 11 '17 at 19:32
  • 1
    Maybe it works but sending notifications fails and you are getting errors in your `laravel.log` file – Marcin Nabiałek Oct 11 '17 at 19:37
0

For the method delay() to work you must add to your Notification implements ShouldQueue

class AccountApproved extends Notification implements ShouldQueue { ... }

and ofc use Illuminate\Contracts\Queue\ShouldQueue; before your class

dns_nx
  • 3,651
  • 4
  • 37
  • 66