I'm developing an app in Laravel. I've models called Account and ShippingAddress. An Account may have one or more ShippingAddress, but a ShippingAddress can only have one Account. So that I'm using a one-to-many relation.
Now I want to implement a functionality that marks a ShippingAddress as "default", and there's can be only one "default Shipping Address" per "Account". I've identified two possible solutions:
- Add a "is_default" column on ShippingAddress table.
- Create a "default_shipping_address" pivot table where I'll store the "account_id" "and shipping_address_id".
Which one is the best solution up to you and why? In case of the second one: how can I implement a one-to-one relation in Laravel through a pivot table?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire