Can u please provide your DB structure?
How to model a hasMany relationship with an extra condition ?
I have a Category model with parent, children relations
The problem is my Category table holds multiple hierarchies from different websites and due to the nature of the project, I don't have a parent_id to uniquely point to a category, so I rely on this structure that adds an extra condition to the relations (parent.website = children.website):
Website Category Parent
A 1 null
A 2 1
Can I do this for relationships:
public function children() {
return $this->hasMany(Category)->where('website', $this->website);
}
And how do I create the migration to reflect it in terms of indexes ?
I believe that is currently not available in Laravel. However, this library that might help u.
https://github.com/topclaudy/compoships
I answered this very same questions two days ago. Check out this thread: https://laracasts.com/discuss/channels/laravel/two-way-pivot-table
Please or to participate in this conversation.