简体   繁体   English

如何用附加关系组织多对多关系:hasMany for拦截表

[英]How to organize many-to-many relations with additional relationship: hasMany for interception table

I have table users and table channels.User can subscribe to channels and unsubscribe many times. 我有桌子用户和桌子频道。用户可以订阅频道并取消订阅很多次。 The task: I need to store all subscription and unsubscription dates for each channel. 任务:我需要存储每个频道的所有订阅和取消订阅日期。 What the best way to do this in Laravel 5? Laravel 5中执行此操作的最佳方法是什么?

I have an idea to store this dates as array like: 我有一个想法来存储此日期为数组,如:

[['subscribe' => date, 'unsubscribe' => date], ...] 

in intersection table(users_channels) field, but is this a best solution? 在交集表(users_channels)字段中,但这是最佳解决方案吗?

And i have an idea to store this date to additional table, but how to create and update this table fields. 我有一个想法可以将此日期存储到其他表中,但是如何创建和更新此表字段。 The only thing that is convenient in this case - is to get all subscription and unsabscribtion dates for user in some channel with hasManyThrough () function 在这种情况下,唯一方便的是-使用hasManyThrough()函数获取某个频道中用户的所有订阅和取消订阅日期

Laravel 5 has Observers, you can check documentation here. Laravel 5有观察者,您可以在这里查看文档。 https://laravel.com/docs/5.4/eloquent#observers . https://laravel.com/docs/5.4/eloquent#observers

You can also use Events. 您也可以使用事件。
https://laravel.com/docs/5.4/eloquent#events https://laravel.com/docs/5.4/eloquent#events

You can check the upcoming information and based on that add subscription trail in database. 您可以检查即将到来的信息,并基于数据库中的添加订阅跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM