nova-field-sortable icon indicating copy to clipboard operation
nova-field-sortable copied to clipboard

Default Sort on Related

Open johnpaulmedina opened this issue 6 years ago • 4 comments

I was writing something to extend the default sort when I came across someone linking to your package. I noticed that you are only attaching the sort on the index and it is not able to sort on the related content.

Any plans on doing this or should I write my own?

johnpaulmedina avatar Oct 05 '18 19:10 johnpaulmedina

Added this to future plans. In the meantime you're more than welcome to make a PR.

Naxon avatar Oct 05 '18 20:10 Naxon

@johnpaulmedina We can make this work with HasMany and MorphMany relationships already.

To make sure that sorting is done among groups only, we can override buildSortQuery() method on the model.

/**
 * Build eloquent builder of sortable. (For spatie/eloquent-sortable package)
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function buildSortQuery()
{
    return static::query()->where('post_id', $this->post_id);
}

gauravmak avatar Oct 11 '18 04:10 gauravmak

@gauravmak do you mean you have the UI (the arrows) showing up in the HasMany grouping?

If so, how? Thanks!

timbroder avatar Feb 04 '19 23:02 timbroder

@timbroder Yes, that was the case as far as I can remember. I was displaying only the records of a group and then sorting had to work among the group records only.

gauravmak avatar Feb 05 '19 04:02 gauravmak