如何监听关系添加事件? [英] How to listen for relation add events?

查看:76
本文介绍了如何监听关系添加事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后端添加相关模型时调用一个函数. 这可以通过使用数据透视模型来实现,但在这种情况下,必须有一些数据透视,否则将不会触发数据透视事件.

I want to call a function when a related model is added in the backend. This can be achieved by using a pivot model but in that case there must be some pivot data, otherwise the pivot model events are not fired.

我不需要任何数据,只需要监听关系添加事件.

I dont need any pivot data but just to listen for the relation added event.

推荐答案

我认为已解决,请参见此文档.他们为多对多关系添加了4个事件:afterAttach, afterDetach, beforeAttach and beforeDetach

I think this was solved see this pull request and API Docs. They added 4 events for Many-to-Many relations : afterAttach, afterDetach, beforeAttach and beforeDetach

这篇关于如何监听关系添加事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆