Two belongsToMany relationships in one? #230
-
I have a scenario in which I am trying to create a merged relationship out of two belongsToMany relationships - it looks something like this: User model:
Ideally I'd like to be able to call something like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @joshstobbs, use Staudenmeir\LaravelMergedRelations\Facades\Schema;
Schema::createMergeView(
'all_projects',
[(new User)->followedProjects(), (new User)->assignedProjects()]
); class User extends Model
{
use \Staudenmeir\LaravelMergedRelations\Eloquent\HasMergedRelationships;
public function projects()
{
return $this->mergedRelationWithModel(Project::class, 'all_projects');
}
} |
Beta Was this translation helpful? Give feedback.
-
Hi @staudenmeir Edit: This works great but Using the example above:
To create an example of the views:
The
How to solve this issue? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick answer. |
Beta Was this translation helpful? Give feedback.
Hi @joshstobbs,
You can merge these relationships with another package of mine:
https://github.com/staudenmeir/laravel-merged-relations