Closed RoyXiang closed 7 years ago
Hi @RoyXiang
Thanks for pull request. Yeah you're right exactly.
But "toBase" method added in 5.2 version. This package supports greater than or equal 5.0 version also. I guess we need to add "applyScopes" method inside to QueryBuilder. Then we can use it like $this->query->applyScopes()->getQuery()
If you could update your pull request as I said above, I will glad to merge it :) :+1:
https://github.com/laravel/framework/blob/5.2/src/Illuminate/Database/Eloquent/Builder.php#L1314
Updated. :) @selahattinunlu
@RoyXiang
I guess you understood me wrong. We need to add a method into our QueryBuilder class. That method should do what Illuminate/Database/Eloquent/Builder::applyScopes method does. And It must also be compatible with the older version. (>=5.0 version)
After some investigation, global scopes on a Eloquent model was introduced in laravel 5.2 for the first time. Before that, we don't need to care about the scopes on a model.
So, I'd prefer to check if toBase
available on $this->query
using method_exists
instead of implementing another applyScopes
.
Again, updated. :)
@RoyXiang
Yeah it's good idea! Thanks for contribution. Merged :)
If a model has some scopes, like a most common one -
SoftDeletes
. If there are some records in the corresponding table in database, and one of them is soft deleted, thetotal
on pagination would still include that deleted one.Refer to this line, I'll suggest using
toBase
instead ofgetQuery
which would apply the scopes to the model.