Mismatch with expected Builder instance and documentation

The documentation states that a custom summarizer should have an instance of Illuminate\Database\Query\Builder passed in, but when I do that, I get the error: Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, Illuminate\Database\Query\Builder given I need to customize a summarizer. Basically I store dollar amounts as absolute numbers in the DB, and I have a transaction_type field that indicates if it's positive or negative. I need the summarizer to handle that, so was thinking something like this:
->summarize(Summarizer::make()
->using(fn (Builder $query): string => $query->where('transactionType.is_negative', 0)->sum('balance') - $query->where('transactionType.is_negative', 1)->sum('balance')))
->summarize(Summarizer::make()
->using(fn (Builder $query): string => $query->where('transactionType.is_negative', 0)->sum('balance') - $query->where('transactionType.is_negative', 1)->sum('balance')))
But it seems no matter what kind of Builder instance I pass in to the using method, i get the same error.
3 Replies
Jon Mason
Jon Mason6mo ago
Can't get past this error. Even the simplest example following the documentation and providing the correct reference gives the error about the wrong builder instance.
->summarize(Summarizer::make()
->label('Total')
->using(fn (\Illuminate\Database\Eloquent\Builder $query): string => $query->sum('balance')))
->summarize(Summarizer::make()
->label('Total')
->using(fn (\Illuminate\Database\Eloquent\Builder $query): string => $query->sum('balance')))
buhbailey
buhbailey5mo ago
Jon, were you ever able to solve this? I am running into the same issue after reviewing the docs. It may be related to the using method. To shortcut my investigation, could you provide any solution that worked for you? I just renamed Eloquent\Builder as EloquentBuilder which was being used elsewhere in the class and it worked. Sorry for the intrusion on something so simple! Also, not sure if this is the best way to handle your issue with absolute values, but I created local scopes for positive and negative. like
public function scopePositive(EloquentBuilder $query): void { $query->whereIn('transaction_type', ['P', 'C', 'F']); }
public function scopePositive(EloquentBuilder $query): void { $query->whereIn('transaction_type', ['P', 'C', 'F']); }
then make simple reference in the summarizer.
Jon Mason
Jon Mason5mo ago
Hmm, I’ll have to try that, I couldn’t ever get past the issue, I just set it aside and figured maybe it would get resolved at some point Love the scope idea, thanks for that!
Want results from more Discord servers?
Add your server
More Posts