2

I am using Laravel scopes to limit what the end user can see based on some provided input, however with my current use-case this is no longer acceptable.

Before applying additional queries, I would like to see what Eloquent method is being called, or at least see whether the ending SQL is performing a SELECT, INSERT or whatever before it is actually executed.

I can see that the Model is loading scopes within a constructor, which leads me to the conclusion that the actual query which would be executed without scopes is somewhere further down the line, however I can't seem to find it.

Is there some point where I can insert scopes (or similar equivalent) to the point right before the actual query is executed?

EDIT: even more confusing is the fact that all() method doesn't go inside Eloquent Builder...

Norgul
  • 4,613
  • 13
  • 61
  • 144

2 Answers2

0

I think you could throw an error, like this:

throw new Exception()

And then use the debug html output. It should have a tab, that shows the last queries. Not the most beautiful idea, but maybe it works.

wschopohl
  • 1,567
  • 1
  • 11
  • 18
0

What I wanted to do is not possible. Scopes are loaded and applied pretty early (before any Eloquent event is fired) upon model instantiation.

I had 2 ideas: one in this post, and this one; none of which worked. In the latter you can see what was the use case I needed, and how I ended up solving it.

Norgul
  • 4,613
  • 13
  • 61
  • 144