Closed LaurentWi closed 6 months ago
Hi
Same problem for me with 6.0 version
You have to make an array of the $notifications an use this method to send :
foreach ($notifications as $notification) { $webPush->queueNotification( $notification['subscription'], $notification['payload'] ); }
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if ($report->isSuccess()) {
// do something
} else {
//$report->getReason()
}
}
And don't forget to autoload
Hi,
I spent over 12 hours looking for solutions ☹ This is how i solve this issue, maybe it is not the best way but it worked for me :
This idea came to me after testing web-push-php in a new project composer and seeing that it worked fine. Hope it will help someone 😊
Setup
PHP 7.2 Last version of webpush
gmp, mbstring, curl, openssl are all enabled
All browsers
All versions
I get the following error message: Fatal error: Uncaught Error: Class 'Minishlink\WebPush\Subscription' not found in ... when using this code: use Minishlink\WebPush\WebPush; use Minishlink\WebPush\Subscription;
// array of notifications $notifications = [ [ 'subscription' => Subscription::create([ 'endpoint' => $endpoint, // Firefox 43+, 'publicKey' => $publicKey, // base 64 encoded, should be 88 chars 'authToken' => $authToken, // base 64 encoded, should be 24 chars ]), 'payload' => 'hello !', ] ];
I have installed the package with composer and i see all files in the directory: Encryption.php MessageSentReport.php Notification.php Subscription.php SubscriptionInterface.php Utils.php VAPID.php WebPush.php
I have seen someone with the same error message in the list of issues here but in his case there was a file missing which is not my case.
Any idea?
Thanks