I need help with relationships in Laravel 5.3.
I have 3 tables: groups (group_id, group_name) businesses (business_id, business_name) payments (payment_id, date)
A group can have many businesses, in the model I created belongsToBusiness
A business can belong to many groups, in the model I created belongsToGroup
I've created a pivot table: business_group (business_id, group_id)
A payment belongs to one group and one business.
When the user views a group I need to display the payments for group with the business name for each payment.
When the user views a business I need to display the payments for business with the group name.
At this point I got dazed and confused.
Which relationship do I use for the payments?
Is it one of these? Has Many Through, Polymorphic Relations, Many To Many Polymorphic Relations
If so, which one?
Someone suggested I add an id field to the business_group pivot table and then a field business_group_id field to the payments table. How do I set up the relationship in the models if I do that?
And how do I retrieve the data to display the payments?
Can someone please help?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire