PHP code example of yassir3wad / nova-realtime-notification
1. Go to this page and download the library: Download yassir3wad/nova-realtime-notification 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/ */
yassir3wad / nova-realtime-notification example snippets
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;
use Laravel\Nova\Notifications\NovaChannel;
use Laravel\Nova\Notifications\NovaNotification;
class AdminNotification extends Notification implements ShouldQueue
{
use Queueable;
private $message;
private $actionPath;
private $actionLabel;
private $level;
public function __construct($message, $actionPath, $actionLabel, $level)
{
$this->message = $message;
$this->actionPath = $actionPath;
$this->actionLabel = $actionLabel;
$this->level = $level;
}
public function via($notifiable)
{
return [NovaChannel::class, 'broadcast'];
}
public function toNova()
{
return (new NovaNotification)
->message($this->message)
->action($this->actionLabel, $this->actionPath)
->icon('bell')
->type($this->level);
}
public function toBroadcast(object $notifiable): BroadcastMessage
{
return new BroadcastMessage([
'message' => $this->message,
'action_label' => $this->actionLabel,
'action_path' => $this->actionPath,
'level' => $this->level,
'duration' => 7000,
]);
}
}
use App\Notifications\AdminNotification;
use App\Models\User;
$user = User::find(1);
$user->notify(new AdminNotification('You have a new admin message!', '/admin/messages', 'View', 'info'));