PHP code example of digitalcloud / advanced-notifications
1. Go to this page and download the library: Download digitalcloud/advanced-notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digitalcloud / advanced-notifications example snippets
// disable/enable all notifications for specific channel
AdvancedNotifications::setChannelStatus('database', false); // true to enable
// get specific channel status
$channelStatus = AdvancedNotifications::getChannelStatus('database');
// disable/enable a specific notification globally- for all users.
AdvancedNotifications::setNotificationStatus(InvoicePaid::class, false); // true to enable
// get a specific notification status
$notificationStatus = AdvancedNotifications::getNotificationStatus(InvoicePaid::class);
// disable/enable a specific notification for a specific notifiable.
$notifiable = \App\User::find(1);
AdvancedNotifications::setNotificationStatusForNotifiable(InvoicePaid::class, $notifiable, false); // true to enable
// get a specific notification status for a specific notifiable.
$notificationStatusForNotifiable = AdvancedNotifications::getNotificationStatusForNotifiable(InvoicePaid::class, $notifiable);
// disable/enable a specific channel for a specific notifiable.
AdvancedNotifications::setChannelStatusForNotifiable('database', $notifiable, false); // true to enable
// get a specific channel status for a specific notifiable.
$channelStatusForNotifiable = AdvancedNotifications::getChannelStatusForNotifiable('database', $notifiable);
namespace App\Notifications;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
use Queueable;
/**
* @var User
*/
private $notifiables;
public function send() {
if($this->getNotifiables()) {
app(\Illuminate\Contracts\Notifications\Dispatcher::class)
->sendNow($this->getNotifiables(), $this);
}
}
public function getNotifiables() {
return $this->notifiables;
}
public function setNotifiables($notifiables) {
$this->notifiables = $notifiables;
}
}
namespace App\Notifications;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
use Queueable;
/**
* @var User
*/
private $notifiables;
public function handle($event) {
// setup notifiable objects, just for illustration
// you can replace this code by your suitable logic
if($event->notifiables) {
$this->setNotifiables($event->notifiables);
}
// send the notification
$this->send();
}
public function send() {
if($this->getNotifiables()) {
app(\Illuminate\Contracts\Notifications\Dispatcher::class)
->sendNow($this->getNotifiables(), $this);
}
}
public function getNotifiables() {
return $this->notifiables;
}
public function setNotifiables($notifiables) {
$this->notifiables = $notifiables;
}
}
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
class NewPurchase
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $notifiables;
public function __construct($notifiables = null)
{
$this->notifiables = $notifiables;
}
}