'Laravel: Target ReportHandlerInterface is not instantiable while building WebPushChannel

I'm trying to implement webpush notification channel in laravel API application. I followed the official instructions at this link but I receive this error message:

{
    "message": "Target [NotificationChannels\\WebPush\\ReportHandlerInterface] is not instantiable while building [NotificationChannels\\WebPush\\WebPushChannel].",
    "exception": "Illuminate\\Contracts\\Container\\BindingResolutionException",
    "file": "/web/htdocs/www.sglive.it/home/apidev/project/vendor/laravel/framework/src/Illuminate/Container/Container.php",
    "line": 1087,
    "trace": [...

My User Model declaration:

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasPushSubscriptions;

My notification object

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;

class TestNotification extends Notification
{
    use Queueable;


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

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     * @param $notification
     * @return WebPushMessage
     */
    public function toWebPush(mixed $notifiable, $notification)
    {
        return (new WebPushMessage)
            ->title('Approved!')
            ->icon('/icon.png')
            ->body('Your account was approved!')
            ->action('View account', 'view_account')
            ->options(['TTL' => 1000]);
    }

}

My controller method

public function sendNotification()
    {
        $user = User::find(3);
        //$user->notify(new TestNotification());
        Notification::send($user, new TestNotification);

        return $this->handleResponse($user);
    }

Any idea on how to solve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source