bnbwebexpertise / laravel-push-notifications

[DEPRECATED] APNs and GCM Push Notifications module for Laravel 5
5 stars 5 forks source link

FatalErrorException in Notification.php line 45: Call to a member function unique() on a non-object #2

Closed noprobz09 closed 7 years ago

noprobz09 commented 7 years ago

Hello,

I tried to use this package but I got error.

"FatalErrorException in Notification.php line 45: Call to a member function unique() on a non-object"

Below is my code.

use Bnb\PushNotifications\Device as BNBDevice;
use Bnb\PushNotifications\Notification as BNBNotification;

public function notification(){
                $notification = new BNBNotification('Hello World !', 'This is a test message');

        $notification
                ->badge(1)
                //->sound('sound')
                ->ttl(1234)
                ->metadata('key1', 'value1')
                ->metadata('key2', 'value2');

        $notification->metadata('custom-id', 1234);

        $notification->push(BNBDevice::apns('device token')->badge(2)->metadata('device-key','demoApns'));

        $results = $notification->send();
}

Any help is much appreciated.

gabsource commented 7 years ago

Hi !

Did not managed to reproduce this error. The unit tests run fine even with Illuminate 5.4 dependencies.

Using php artisan tinker on a Laravel 5.2 project, the following snippet does not produce any error :

use Bnb\PushNotifications\Device as BNBDevice;
use Bnb\PushNotifications\Notification as BNBNotification;
$notification = new BNBNotification('Hello World !', 'This is a test message');
$notification->badge(1)->ttl(1234)->metadata('key1', 'value1')->metadata('key2', 'value2');
$notification->metadata('custom-id', 1234);
$notification->push(BNBDevice::apns('device token')->badge(2)->metadata('device-key','demoApns'));
$results = $notification->send();

image