Laravel推送通知,非静态方法称为静态

时间:2017-08-03 09:29:10

标签: php ios laravel-5 push-notification

我正在尝试实施this库,以便向iOS应用发送推送通知。我所有的配置都很好。当我测试此页面上提供的代码段时,如下所示:

PushNotification::app('appNameIOS')
                ->to($deviceToken)
                ->send('Hello World, i`m a push message');

它抛出了这个错误:

  

非静态方法   Davibennun \ LaravelPushNotification \ PushNotification :: Message()应该   不能静态调用

正确,因为当我打开课程时,没有这样的静态方法。有一个,但这不是静态的。我究竟做错了什么?有什么帮助吗?

修改1 我已生成配置文件:

return array(

    'hasalty_ios'     => array(
        'environment' =>'development',
        'certificate' =>base_path('pem.p12'),
        'passPhrase'  =>'',
        'service'     =>'apns'
    ),
    'hasalty_android' => array(
        'environment' =>'production',
        'apiKey'      =>'yourAPIKey',
        'service'     =>'gcm'
    )

);

修改2

enter image description here

我的Laravel版本为5.5.31

2 个答案:

答案 0 :(得分:1)

如果您正确配置了库,则应使用

use Pushnotification;

而不是

use Davibennun\LaravelPushNotification\PushNotification;
  

当用户引用Cache Facade上的任何静态方法时,Laravel将从服务容器中解析缓存绑定,并针对该对象运行所请求的方法(在本例中为get)。   How Facades Work

修改

您必须在使用之前生成配置文件:

php artisan vendor:publish --provider="Davibennun\LaravelPushNotification\LaravelPushNotificationServiceProvider" --tag="config"

答案 1 :(得分:0)

尝试使用此代码:

改为use Pushnotification use Davibennun\LaravelPushNotification\PushNotification;

enter image description here