lundi 11 janvier 2016

Laravel paginator overrides select (or specifically ->count() does)

If I am building a query, and add a select statement, it will be overridden if I use ->paginate(50) (because ->paginate() uses ->count() that seems to override existing select stakements).

I.e.:

$users = User::whereActive(1)->addSelect('some-custom-select-statement')->paginate(10); // wont work. 'some-custom-select-statement' will not be returned

Or if I even did:

$users = User::whereActive(1)->addSelect('some-custom-select-statement')->having('some-custom-select-statement', '>', 0)->count(); // wont work. 'some-custom-select-statement' will not be returned

How do I overcome this? Only solution right now is to skip using paginator.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire