dyaa/pushover
Laravel 5 package for sending Pushover.net notifications to iOS/Android. Configure your app token and user key, then use a simple Facade API to push messages and optionally set URL, callback, sound, and more.
Installation:
composer require dyaa/pushover:dev-master
Add the service provider to config/app.php:
'providers' => [
// ...
Dyaa\Pushover\PushoverServiceProvider::class,
],
Publish Config:
php artisan vendor:publish --provider="Dyaa\Pushover\PushoverServiceProvider"
Configure .env with your Pushover API token and user key:
PUSHOVER_API_TOKEN=your_api_token
PUSHOVER_USER_KEY=your_user_key
First Use Case: Send a notification in a controller or command:
use Dyaa\Pushover\Facades\Pushover;
Pushover::send('Hello from Laravel!', 'This is your first Pushover message.');
Basic Notifications:
Pushover::send('Title', 'Message body', [
'priority' => 1, // 0 (quiet) to 2 (loud)
'url' => 'https://example.com',
'url_title' => 'View Details',
]);
Grouped Notifications:
Pushover::sendToGroup('GroupName', 'Title', 'Message');
Silent Notifications (Priority 0):
Pushover::send('Low Priority', 'This won\'t make a sound.', ['priority' => 0]);
Integration with Events:
// In an Event class
public function handle()
{
Pushover::send('Event Triggered', 'User ' . $this->user->name . ' performed action.');
}
Queueing Notifications:
Pushover::queue('Title', 'Message'); // Uses Laravel's queue system
Dynamic Recipients:
$users = User::where('is_admin', true)->get();
foreach ($users as $user) {
Pushover::sendToUser($user->pushover_key, 'Alert', 'New admin activity detected.');
}
Conditional Notifications:
if ($user->prefers_pushover) {
Pushover::send('Welcome', "Hi {$user->name}, you're all set up!");
}
Logging Failures:
try {
Pushover::send('Critical Alert', 'Server down!');
} catch (\Exception $e) {
Log::error("Pushover failed: " . $e->getMessage());
}
Deprecated Laravel Version:
dev-master branch may not be fully compatible with newer Laravel versions (e.g., 8+). Test thoroughly or fork the repo for updates.Missing .env Configuration:
PUSHOVER_API_TOKEN/PUSHOVER_USER_KEY will cause silent failures. Verify with:
if (!config('pushover.api_token')) {
throw new \RuntimeException('Pushover API token not configured.');
}
Priority Overrides:
1. Explicitly set priority to avoid unexpected loud notifications:
Pushover::send('Alert', 'Message', ['priority' => 0]); // Quiet
Queue Stuck Jobs:
pushover queue connection is properly configured in config/queue.php. Monitor failed jobs in failed_jobs table.Rate Limiting:
foreach ($notifications as $notification) {
Pushover::send($notification['title'], $notification['message']);
sleep(1); // 1-second delay between messages
}
Enable Debugging:
Add to config/pushover.php:
'debug' => env('PUSHOVER_DEBUG', false),
This logs raw API responses to storage/logs/pushover.log.
Test with a Dummy Token: Use Pushover’s sandbox token during development to avoid hitting real limits.
Check HTTP Client:
The package uses Laravel’s HTTP client. Verify no middleware (e.g., TrustProxies) interferes with the request.
Customize the HTTP Client: Override the default client in a service provider:
$this->app->singleton(\Illuminate\Http\Client\Factory::class, function ($app) {
return \Illuminate\Http\Client\PendingRequest::macro('pushover', function () {
return $this->withOptions(['debug' => true]);
});
});
Add Custom Fields:
Extend the Pushover facade to support additional Pushover API fields (e.g., sound, timestamp):
// In a custom facade class
public function sendWithSound($message, $sound = 'magic')
{
return $this->send($message, null, ['sound' => $sound]);
}
Mock for Testing: Use Laravel’s HTTP mocking in tests:
$this->mock(\Illuminate\Http\Client\PendingRequest::class)
->shouldReceive('post')
->once()
->andReturnResponse();
How can I help you explore Laravel packages today?