-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested where not working #60
Comments
What does the method calling Also, if you're passing anymore input to And it may also help to see the |
The call to filter() is The only other filters are for two foreign keys, and I'm just passing the ID so nothing complicated there
The media relationship comes from the medialibrary package, but I've removed that entirely from the filter call and still experience the same result. |
I have a feeling there may be something in your From what it is printing out, I am assuming the input passed to [
'search' => 'a',
'category' => 2
]; Because from what that sql shows, the limit should be 5 from your paginator call, not 2 and if you remove the |
The pagination param issue is just because I changed that value in the code between my first post and second here. Right now pagination is set to 5 per page and the query is:
However, you're definitely right. Something is clashing between this code and the medialibrary code. If I remove the medialibrary interface and trait from my Listing model, the generated query is correct. |
For what it's worth, I just added a global scope to the Listing model to only show results with a renewal date in the future. When I did that, the query changed to: |
Sorry for the barrage of updates. If I run the search without any filters, this is the query generated with my new global scope in place:
As you can see, the date is correct and not "App\Listing". Additionally, if I run through my filters (category and manufacturer) WITHOUT specifying a search keyword, the query is correct. It is something specifically happening when using the where method INSIDE the anonymous function. If I simply use a public function search($search)
{
return $this->where('description', 'LIKE', "%$search%");
} It works fine. But as soon as I do: public function search($search)
{
return $this->where(function($q) use ($search)
{
return $q->where('description', 'LIKE', "%$search%");
});
} It screws up. |
What version of Laravel and laravel-medialiabrary are you using? |
7.1.3 medialibrary |
Looking into this, I think it may be a Laravel issue... Do you have |
Yes indeed. |
Then it definitely looks like a Laravel issue. If you removed that and added it as a global scope instead of a property, it should fix this issue. What is going on is that in the nested |
Confirmed. Adding a global scope and removing the withCounts property did fix this issue. |
Awesome! I'll open an issue in Laravel/send a PR to patch the issue |
This is my filter:
But this is the query that's being run:
For some reason, the first instance of
$search
is returning the classname of the model instead of the search term that's being passed through the query string. I'm unsure if I've just set this up incorrect or if it's a bug.The text was updated successfully, but these errors were encountered: