Front end uses pagination and filtering

spotony - 4 months ago

I use belongsToMany pagination and filtering!

$relatives = $this->getRelatives();

        return $this->belongsToMany(
            ApartmentModel::class,
            'stores_apartment_categories',
            'related_id',
            'entry_id'
        )->wherePivotIn('related_id', $relatives->ids());

Seek advice

ryanthompson - 4 months ago

Sorry I am not sure what you are asking? I don't see any pagination in there. Is that what you need help with?

spotony - 4 months ago

In one-to-many database operations, add the paging and filtering functions as above. Seek advice or develop documentation

ryanthompson - 4 months ago

Ah I see:

You can filter like this:

$this->getRelatives()->where('foo', 'bar');

And end with a pagination object like this:

$pagination = $this->getRelatives()->where('foo', 'bar')->paginate();

That will return a Laravel paginator.

spotony - 4 months ago

Thank you for your help! But unfortunately, it may be my description of the problem did not notice the details!

$relatives = $this->getRelatives();

        return $this->belongsToMany(
            ApartmentModel::class, // This model uses the ability to filter and search
            'stores_apartment_categories',
            'related_id',
            'entry_id'
        )->wherePivotIn('related_id', $relatives->ids());

Such as articles, classified into categories and articles. When I choose a particular category, the number of articles in this category is particularly large! I would expect to give users a search and then detail the screening. Not category need to filter and search Oh! Thank you for giving more help!

$this->getRelatives()->where('foo', 'bar'); // Where the screening is to operate on the category Oh!