Using query builder and filter by morphTo relationship not works. #813
Unanswered
mobasherfasihi
asked this question in
General
Replies: 2 comments 2 replies
-
Hi @mobasherfasihi . QueryBuilder::for(MailJob::class) that line returns an new instance of 'Spatie\QueryBuilder\QueryBuilder'. Please tell me what version of the package and laravel you are using. |
Beta Was this translation helpful? Give feedback.
0 replies
-
"notCompleted()" method seems to be an scope. class MailJob extends Model
{
public function mailable()
{
return $this->morphTo();
}
public function scopeNotCompleted($query)
{
return $query->whereHasMorph('mailable', fn ($q) => $q->whereNotNull('name'));
}
}
...
MailJob::notCompleted()->get() now you can try this.. QueryBuilder::for(MailJob::notCompleted())->get(); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the following model
And then when I want to filter by mailable, it gives
Subject class "Illuminate\Database\Query\Builder" is invalid.
Beta Was this translation helpful? Give feedback.
All reactions