Maybe try to turn on logging of SQL queries and check if they are OK.
Eloquent/Query builders are great for 99% of things that you want to do with the database but throw in anything that's not "standard" and you will get a lot of wtfs
Thanks, Mike. I'll go ahead and try that. It's a good suggestion - I usually rely on debugbar to check my queries, but since it didn't get through, it failed.
Also, in my apply()
method, I already tried a dd($builder->toSql());
right after addding the whereAs condition, but that didn't give me any output, so to be honest, I believe it's even before that - sounds like I'll have to dig into the query builder code to find out what's happening that is preventing my statement to execute.
Just for my sanity - what I wrote above seemed correct to you?
From the snippets you've posted it does seem correct to me and it works with simple $builder->where()
so the problem is not with adding global scopes or the trait since it is getting booted.
I would bet on morphing or simple mistake like wrong column in where's. Also did you try to build the query outside of the global scopes? For example in tinker or just to test it in controller?
Anyway could you post your tables?
Sigh - I just found some issues on githbub that confirm this is not supported. There is no support for doing whereHas on morphTo relations.
It probably makes sense, because a morphTo can morph to different models, and the filter you add may not work for all related models, but I think we should be able to fix it though.
I'm going to look into it a bit more, and see if I could create a PR, or find a decent (alternative) solution for now.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community