Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save casperboone/23d4919d0086d115137364489b533114 to your computer and use it in GitHub Desktop.
Save casperboone/23d4919d0086d115137364489b533114 to your computer and use it in GitHub Desktop.
Laravel Pushover Notifications - Basic Setup Example
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverChannel;
use NotificationChannels\Pushover\PushoverMessage;
class InvoicePaidNotification extends Notification
{
use Queueable;
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [PushoverChannel::class];
}
/**
* Get the Pushover representation of the notification.
*
* @return PushoverMessage
*/
public function toPushover()
{
return PushoverMessage::create("hi there");
}
}
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* Pushover user token as a string or an instance of PushoverReceiver.
*
* @return string
*/
public function routeNotificationForPushover()
{
return 'W3nsdfdspblnl23jf83szO8HSSAOwK'; // Fake example of course
}
}
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, SparkPost and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'sparkpost' => [
'secret' => env('SPARKPOST_SECRET'),
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
'pushover' => [
'token' => 'am8s39fjash3874j3mq3f9eeovruzp4', // Pushover application token (this is a fake one ;) )
],
];
<?php
use App\Notifications\InvoicePaidNotification;
use App\User;
class PushoverTest extends TestCase
{
public function testBasicExample()
{
$user = new User();
$user->notify(new InvoicePaidNotification());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment