Laravel:构建WebPushChannel时,目标reporthandlerinterface无法即时
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我只是通过
PHP Artisan优化解决了这个问题,以清除所有Laravel Cache:clear
So I just resolved this very issue clearing all laravel cache using
php artisan optimize:clear