Laravel通知保存到不同的模式

发布于 2025-02-07 14:02:22 字数 184 浏览 0 评论 0原文

我将如何强制将不同的通知保存在不同的模式中。

例如,我有两个通知表client.botificationsbusiness.notifications在我的数据库中。 我希望将所有通知保存到业务架构中,但一个通知除外,我希望将其保存到客户端架构中。

这一点可能吗?

How would I force different notifications to be saved in different schemas.

For example, I have two notification tables client.botifications and business.notifications in my DB.
I want all notifications to be saved to the Business schema with the exception of one notification, which I would like to be saved to the Client Schema.

Is this at all possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2025-02-14 14:02:22

必须进行一些推定,我假设您是默认数据库连接,在这种情况下,client连接以支持您的辅助方案。如果这是相应地互换的相反方式。而且您通知是用户。

如果您仔细阅读通知逻辑,则在某个时候,它将调用$ noctififififiable- noctifications() - > creation(); 这是在通知类中的,它获取notification( )关系方法,来自这个特质。为了避免所有用户操作,可以保存在错误的连接上,当您调用Notify时,我只会更改连接,何时应将其保存在客户端连接上。

$user = User::find($someUser);
$user->setConnection('client');
$user->notify(YourClientNotification());

Some presumptions must be made, i assume you a default database connection and in this case a client connection to support your secondary scheme. If it is the other way around interchange them accordingly. And you notifiable is a user.

If you read through the notification logic, at some point it calls $notifiable->notifications()->create(); This is on the notifiable class, which gets it notification() relationship method, from this trait. To avoid all the users operation, being saved on the wrong connection, i would just change the connection when you call the notify, when it should be saved on the client connection.

$user = User::find($someUser);
$user->setConnection('client');
$user->notify(YourClientNotification());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文