广播通知

请确保此包已经安装了 - 并将 @livewire('notifications') 插入到 Blade 布局文件中。

默认情况下,Filament 通过 Laravel session 发送闪存通知。假如你希望通知实时“广播”给用户,可以用于在队列任务完成处理后从队列任务中发送临时成功消息。

可使用Laravel Echo进行本地集成。确保已经安装了 Echo, 以及服务端websocket集成如Pusher。

发送通知

有多种方法可用于发送广播通知,取决于哪一种更适合你。

你可以使用fluent API:

use Filament\Notifications\Notification;
 
$recipient = auth()->user();
 
Notification::make()
->title('Saved successfully')
->broadcast($recipient);

或者,使用 notify() 方法:

use Filament\Notifications\Notification;
 
$recipient = auth()->user();
 
$recipient->notify(
Notification::make()
->title('Saved successfully')
->toBroadcast(),
)

此外,可使用传统Laravel 通知类返回通知给 toBroadcast() 方法:

use App\Models\User;
use Filament\Notifications\Notification;
use Illuminate\Notifications\Messages\BroadcastMessage;
 
public function toBroadcast(User $notifiable): BroadcastMessage
{
return Notification::make()
->title('Saved successfully')
->getBroadcastMessage();
}

需要帮助? 加入论坛 或者打开 GitHub讨论

喜欢Filament?

Filament 中文文档由 laravel-filament.cn 翻译整理。站长用爱发电,希望为英文阅读不畅的朋友提供快速掌握Filament框架的途径。文档的翻译,社区的运营维护都需要时间精力上的付出。如果文档社区使你受益,如果你想支持站长...

打赏