Edujugon / PushNotification

PHP and Laravel Package to send push notifications to Android and IOS devices.
MIT License
478 stars 159 forks source link

FCM/GCM Usage #11

Closed zanechua closed 7 years ago

zanechua commented 7 years ago

Sorry for having to create another issue so quick but i can't seem to utilise the package if I declare an instance of the facade.

$push = new PushNotification('fcm');

$push->setMessage([
    'notification' => [
        'title'=>'This is the title',
        'body'=>'This is the message',
        'sound' => 'default'
    ],
    'data' => [
        'extraPayLoad1' => 'value1',
        'extraPayLoad2' => 'value2'
    ]
])
->setDevicesToken('token'); 

Having the above code will throw the following error:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Edujugon\PushNotification\Facades\PushNotification::setMessage()

Edujugon commented 7 years ago

@zanechua

Notice that the above code is not using the facade so kindly confirm your use statement at the head of your class is something like this:

use Edujugon\PushNotification\PushNotification;

And no like this:

use Edujugon\PushNotification\Facades\PushNotification;

Edujugon commented 7 years ago

@zanechua

If you prefer using Facade, you could do something like this:

PushNotification::setService('fcm')
                            ->setMessage([
                                 'notification' => [
                                         'title'=>'This is the title',
                                         'body'=>'This is the message',
                                         'sound' => 'default'
                                         ],
                                 'data' => [
                                         'extraPayLoad1' => 'value1',
                                         'extraPayLoad2' => 'value2'
                                         ]
                                 ])
                            ->setApiKey('Server-API-Key')
                            ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])
                            ->send()
                            ->getFeedback();

In that case, yeah, you should use the follow statement: use Edujugon\PushNotification\Facades\PushNotification;

zanechua commented 7 years ago

ah. It needs to import the class directly?

Usually when i import packages, I usually just do

use PushNotification;

Does this not work here?

Edujugon commented 7 years ago

If you want to use Facade, you should set this statement:

use Edujugon\PushNotification\Facades\PushNotification;

As you already know, Facade provides a "static" interface to the class that is available in the application's service container.

Otherwise, if you prefer no to use Facade, then you have to set the below statement:

use Edujugon\PushNotification\PushNotification;

Let me know if the change made it works

zanechua commented 7 years ago

ah I see. Thanks @Edujugon !

I'll stick with the Pure Facade Method. Cheers!