Closed Cannonb4ll closed 6 years ago
Can you provide a code example?
Closing due to paginateFilter()
calls the builder's paginate()
method and this sounds like an issue with the query itself and not the paginateFilter()
method.
We can reopen if there is an example that will replicate this behavior.
@Cannonb4ll you can use the second parameter to specify what you want:
paginateFilter(perPage, ['*'])
or
paginateFilter(perPage, ['companies.*'])
or
paginateFilter(perPage, ['companies.*', 'company_user.*'])
or
paginateFilter(perPage, ['companies.*', 'company_user.*', 'user.*'])
@Tucker-Eric Create the following relation:
user -> company_user <- companies
The table company_user is a pivot table, if I do the following methods, see the difference:
paginate
<- Laravel's original method:
$companies = auth()->user()->companies()
->latest()
->filter(request()->all())
->paginate();
dd($companies->first());
paginateFilter
<- This package's method:
$companies = auth()->user()->companies()
->latest()
->filter(request()->all())
->paginateFilter();
dd($companies->first());
You can see, the relations are now empty when using paginateFilter()
@Cannonb4ll I was able to reproduce this and it should be fixed in https://github.com/Tucker-Eric/EloquentFilter/commit/5583402dd83234c1dcada8d42a16a70e9fa94060
Are you able to pull the latest (dev-master
) and confirm this is resolved?
@Tucker-Eric Confirmed and is resolved with dev-master
!
Awesome! Updated in https://github.com/Tucker-Eric/EloquentFilter/releases/tag/1.3.2
When using the method
paginateFilter()
on a model with pivot table, this pivot table is not present inside the model. When changing back topaginate()
the pivot model is back.companies - company_user - users
In this case, if I would get all the users inside a company, and there would be any additional data inside the pivot table, it would be added inside the 'relations' object inside the model, but this is not present.