Laravel:构建WebPushChannel时,目标reporthandlerinterface无法即时

发布于 2025-01-29 22:28:14 字数 2100 浏览 2 评论 0原文

我正在尝试在Laravel API应用程序中实现WebPush通知频道。 在此链接中

{
    "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": [...

我遵循官方说明 模型声明:

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

我的通知对象

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

}

我的控制器方法

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

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

对如何解决此问题有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-02-05 22:28:14

因此,我只是通过PHP Artisan优化解决了这个问题,以清除所有Laravel Cache:clear

So I just resolved this very issue clearing all laravel cache using php artisan optimize:clear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文