hope you’re having a good day.
I’m using Laravel 8. I have three models and I need those models "entangled", so to speak.
So, I have three basic tables
areas,threats,positions --- id name
So the relationship needed is something like this:
t1and vice versa. (Many to Many)
t2(Many to Many)
My approach so far is this:
- For the first relationship I have a belongsToMany realtionship defined on my models (
- For the second relationship, I have created a custom pivot model for the pivot table, in that model I defined the second many to many relationship (
So far, the first relationship can be saved by doing
Now, for the second relationship, how can I attach the related models?
My last resort is to query the saved custom pivot model and attach the
t2 model(s), but I wanted to ask first if there’s a cleaner, eloquent-laravel way to do this.
Any advice would help. Thanks in advance for taking your time.