Laravel - query builder - left join polymorphic relationship, distinct only
|Added at||2017-01-05 19:01|
So I'm using Vue 2.0 and Laravel 5.3 to create an application.
I've implemented my own sortable table with Vue, using the built-in pagination provided by Laravel.
Everything's working perfect - except, I'm trying to left join a "media" polymorphic table, so I can show an image in my table.
To enable sorting, I've had to use the query builder, as you can't sort on a relationship using Eloquent (AFAIK).
I define my relationships like:
Which work great. However, how exactly do I left join a polymorphic relationship, without repeating (duplicating) any of the rows?
I've got this:
Which does show media (if it has a relation in the polymorphic table). However, if for instance I have 5 images (media) for 1 particular inventory item, my query repeats the inventory for however media there are, which in my case it's repeated 5 times.
This is my select query:
I think I need to use a groupBy, but I'm not sure where I define it. If I do
Has anyone been in a similar situation or know where to put my groupBy to show 1/distinct inventory items?
I was able to fix by using:
and then setting