daltcore/pushover
Laravel package for sending Pushover.net notifications to iOS/Android. Includes a facade/service provider, simple push(title, message) API, and options for URL, callback, sound, and more. Configure with your app token and user key.
Installation:
composer require daltcore/pushover
Add the service provider to config/app.php:
'providers' => [
// ...
DALTCORE\Pushover\PushoverServiceProvider::class,
],
Configuration: Publish the config file:
php artisan vendor:publish --provider="DALTCORE\Pushover\PushoverServiceProvider" --tag=config
Update .env with your Pushover API token and user key:
PUSHOVER_TOKEN=your_api_token
PUSHOVER_USER_KEY=your_user_key
First Use Case: Send a basic notification in a controller or command:
use DALTCORE\Pushover\Pushover;
public function sendNotification()
{
$pushover = app(Pushover::class);
$pushover->send('Hello from Laravel!', 'This is a test message.');
}
Sending Notifications:
Use the Pushover facade or injected service to send messages:
Pushover::send('Title', 'Message body', [
'priority' => 1, // 0 (lowest) to 2 (highest)
'url' => 'https://example.com',
'url_title' => 'View Details',
]);
Integration with Laravel Events:
Trigger notifications on events (e.g., user.registered):
use DALTCORE\Pushover\Events\PushoverNotification;
event(new PushoverNotification('User Registered', 'New user signed up: ' . $user->email));
Queueing Notifications:
Dispatch notifications to a queue (requires queue config):
Pushover::queue('Title', 'Message', ['priority' => 1]);
Dynamic Recipients: Fetch user keys from a database and loop through them:
$admins = User::where('is_admin', true)->get();
foreach ($admins as $admin) {
Pushover::send('Alert', 'New issue reported', [], $admin->pushover_key);
}
Customizing Templates:
Extend the Pushover class to add reusable templates:
class CustomPushover extends Pushover {
public function alert($message, $severity = 'warning') {
$priority = $severity === 'critical' ? 2 : 1;
$this->send('Alert: ' . $severity, $message, ['priority' => $priority]);
}
}
Logging Failures:
Override the send method to log failed notifications:
Pushover::extend(function ($app) {
$pushover = new Pushover($app);
$pushover->afterSend(function ($response, $data) {
if ($response->failed()) {
Log::error('Pushover failed', ['data' => $data, 'response' => $response]);
}
});
return $pushover;
});
Deprecated Laravel Version: The package was last updated in 2019 for Laravel 5.x. Test thoroughly in Laravel 8/9+ due to potential compatibility issues (e.g., dependency conflicts, facades).
No Retry Logic: Failed notifications are not retried by default. Implement a queue job with exponential backoff for critical alerts:
Pushover::queue('Title', 'Message')->onQueue('high')->delay(now()->addMinutes(1));
Rate Limits: Pushover has rate limits. Cache user keys and batch notifications to avoid hitting limits.
Missing Error Handling: The package lacks built-in error handling for invalid API tokens or user keys. Validate inputs:
if (!config('pushover.token') || !config('pushover.user_key')) {
throw new \RuntimeException('Pushover credentials not configured.');
}
Check Responses: Log the raw response to debug issues:
$response = Pushover::send('Title', 'Message');
Log::debug('Pushover Response', ['status' => $response->status(), 'body' => $response->body()]);
Test with Sandbox: Use Pushover’s sandbox to test without real notifications.
Verify Endpoints:
Ensure the PUSHOVER_URL in config is correct (defaults to https://api.pushover.net/1/messages.json).
Custom HTTP Client: Replace the underlying HTTP client (e.g., for mocking in tests):
Pushover::extend(function ($app) {
$client = new \GuzzleHttp\Client(['base_uri' => config('pushover.url')]);
return new Pushover($app, $client);
});
Add Attachments:
Extend the package to support file attachments (Pushover API supports this via attachment parameter):
$pushover->send('Download Available', 'New file ready', [
'attachment' => Storage::disk('s3')->url('file.pdf'),
]);
Multi-User Notifications: Create a helper method for broadcasting to multiple users:
Pushover::extend(function ($app) {
$pushover = new Pushover($app);
$pushover->toMany = function ($title, $message, $userKeys) {
foreach ($userKeys as $key) {
$this->send($title, $message, [], $key);
}
};
return $pushover;
});
How can I help you explore Laravel packages today?