Skip to content
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

Argument 1 passed to App\Client::App\{closure}() must be an instance of Illuminate\Database\Eloquent\Builder, instance of Staudenmeir\LaravelCte\Query\Builder given #34

Closed
Healyhatman opened this issue Dec 1, 2021 · 1 comment

Comments

@Healyhatman
Copy link

Healyhatman commented Dec 1, 2021

Often, for reasons I don't understand, type-hinting a closure as Eloquent/Builder fails because it's apparently been passed a CteBuilder instead.

Why does this happen when as far as I can tell the particular scope isn't using any CTE functions?

For example, this:
\App\Client::whereIn('SYSID', function($q) { dd($q); })->first();
tells me that $q is a CteBuilder.

Client doesn't use QueriesExpressions, extends normal Model class. I don't know why it would be insisting on using the CTE builder in that function.

@staudenmeir
Copy link
Owner

staudenmeir commented Dec 2, 2021

Any closure that you could type-hint with Eloquent\Builder before installing the package, still works the same.

Methods like whereIn() pass a base query builder (Illuminate\Database\Query\Builder) into the closure, not an Eloquent builder. The package extends the query base builder with Staudenmeir\LaravelCte\Query\Builder globally and that's now passed into the closure. Because it's a subclass, a base query builder type-hint still works.

You can pass an Eloquent builder to whereIn(), but you don't get one in the closure:

\App\Client::whereIn('SYSID', System::select('id'))->first();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants