我无法在Laravel中发送通知。我应该如何解决此错误?
Call to undefined method Illuminate\Database\Query\Builder::routeNotificationFor()
in Builder.php line 2123
at Builder->__call('routeNotificationFor', array('WebPush'))
at call_user_func_array(array(object(Builder), 'routeNotificationFor'), array('WebPush')) in Builder.php line 1015
at Builder->__call('routeNotificationFor', array('WebPush')) in WebPushChannel.php line 31
at WebPushChannel->send(object(Builder), object(PushDemo)) in ChannelManager.php line 77
at ChannelManager->sendNow(array(object(Builder)), object(PushDemo)) in ChannelManager.php line 43
at ChannelManager->send(array(object(Builder)), object(PushDemo)) in Facade.php line 217
at Facade::__callStatic('send', array(object(Builder), object(PushDemo))) in PushController.php line 36
我的环境有点特别:我正在建立PWA Laravel 5.1
具有laravel-notification-channels / backport的通知backport
Webpush:laravel-notification-channels / webpush
我尝试了Notification Facade,还尝试了user-> notify()
我的服务人员工作正常,清单json正常。
PushController:
public function store(Request $request){
$this->validate($request,[
'endpoint' => 'required',
'keys.auth' => 'required',
'keys.p256dh' => 'required'
]);
$endpoint = $request->endpoint;
$token = $request->keys['auth'];
$key = $request->keys['p256dh'];
$user = Auth::user();
$user->updatePushSubscription($endpoint, $key, $token);
return response()->json(['success' => true],200);
}
public function push2(){
Notification::send(User::all(),new PushDemo);
return redirect()->back();
}
/**
* Send Push Notification
*
* @return \Illuminate\Http\Response
*/
public function push($id, Request $request){
// Notification::send(User::all(),new PushDemo);
// return redirect()->back();
$user = User::findOrFail($id);
$user->notify(new PushDemo());
return redirect()->back();
}
PushDemo扩展了通知:
public function via($notifiable)
{
return [WebPushChannel::class];
}
public function toWebPush($notifiable, $notification)
{
return (new WebPushMessage)
->title('Hi dude')
->icon('images/icons/izzy-icon-192x192.png')
->body('Great, Push Notifications work!')
->action('View App', 'notification_action');
}
用户:
use Notifiable;
use HasPushSubscriptions;
每次发送5xx错误时都无法发送通知。 我想念什么吗?