简体   繁体   中英

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?

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?

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

Laravel 5 has Observers, you can check documentation here. https://laravel.com/docs/5.4/eloquent#observers .

You can also use Events.
https://laravel.com/docs/5.4/eloquent#events

You can check the upcoming information and based on that add subscription trail in database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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