Nova 通知允许您向 Nova 用户通知应用程序中的事件,例如报告准备下载或需要关注的发票。Nova 通知显示在侧滑菜单中,可以通过 Nova 顶部导航菜单中的“铃铛”图标访问。

要发送通知,您只需将 NovaNotification 实例发送到用户的 notify 方法。当然,在开始之前,您应该确保您的用户模型是 可通知的。
Nova 通知可以通过 NovaNotification 类生成,该类提供了方便的方法,如 message、action、icon 和 type。当前支持的通知类型包括 success、error、warning 和 info
use Laravel\Nova\Notifications\NovaNotification;
use Laravel\Nova\URL;
$request->user()->notify(
NovaNotification::make()
->message('Your report is ready to download.')
->action('Download', URL::remote('https://example.com/report.pdf'))
->icon('download')
->type('info')
);您也可以通过在通知的 via 方法返回的通道数组中包含 NovaChannel 来发送 Nova 通知
use Laravel\Nova\Notifications\NovaNotification;
use Laravel\Nova\Notifications\NovaChannel;
use Laravel\Nova\URL;
/**
* Get the notification's delivery channels
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [NovaChannel::class];
}
/**
* Get the nova representation of the notification
*
* @return array
*/
public function toNova()
{
return (new NovaNotification)
->message('Your report is ready to download.')
->action('Download', URL::remote('https://example.com/report.pdf'))
->icon('download')
->type('info');
}在定义通知操作时,可以调用 openInNewTab 方法来指示 Nova 在新的浏览器标签页中打开给定的 URL
->action(
'Download', URL::remote('https://example.com/report.pdf')
)->openInNewTab()Nova 使用由 Steve Schoger 提供的免费 Heroicons 图标集。因此,您只需在向 Nova 通知提供 icon 方法时指定其中一个图标的名称即可。
如果您希望完全禁用 Nova 中的通知,您可以从 App/Providers/NovaServiceProvider 中调用 withoutNotifications 方法
use Laravel\Nova\Nova;
/**
* Boot any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
Nova::withoutNotificationCenter();
}默认情况下,Nova 在通知中心内有未读通知时会显示一个视觉指示器。如果您希望 Nova 显示未读通知的数量,您可以从您的 App/Providers/NovaServiceProvider 中调用 showUnreadCountInNotificationCenter 方法。
use Laravel\Nova\Nova;
/**
* Boot any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
Nova::showUnreadCountInNotificationCenter();
}