Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Doesn't work with Spatie's Laravel QueryBuilder #487

backstageel started this conversation in General
Discussion options

Describe the bug
Seems Like this Package doesn't work when using Spatie's Laravel query builder to fetch the data (https://github.com/spatie/laravel-query-builder). I've checked that package and they don't override newEloquentBuilder() method, so all should work.

By not working i mean no cache data is returned and the query still hits the database.

Eloquent Query
This query don't work

$student = QueryBuilder::for(Student::class)
 ->join('entidades', 'entidades.id', '=', 'alunos.entidade_id')
 ->where('entidades.user_id', $user->id)
 ->first();

But this work:

$student = Student::join('entidades', 'entidades.id', '=', 'alunos.entidade_id')
 ->where('entidades.user_id', $user->id)
 ->first();

Stack Trace
No stack trace, because no error is generated. Just no data is cached

Environment

  • PHP: 7.3.6
  • OS: Ubuntu 19.04
  • Laravel: 5.8.29
  • Model Caching: 0.6.1
  • Spatie Laravel Query Builder: 1.17.5
You must be logged in to vote

Replies: 7 comments

Comment options

@backstageel Thanks for submitting your issue. This package will not work with third-party query builders, only with Laravel's query builder. Sorry.

You must be logged in to vote
0 replies
Comment options

Actually, i got this Working...

It was as simple as creating a custom builder class that extends Spatie's QueryBuilder and apply the traits from this package on it:

namespace App\Builders;
use GeneaLabs\LaravelModelCaching\Traits\Buildable;
use GeneaLabs\LaravelModelCaching\Traits\BuilderCaching;
use GeneaLabs\LaravelModelCaching\Traits\Caching;
use Spatie\QueryBuilder\QueryBuilder;
class CustomBuilder extends QueryBuilder
{
 use Buildable;
 use BuilderCaching;
 use Caching;
}
You must be logged in to vote
0 replies
Comment options

I'll add this to the documentation, thanks!

You must be logged in to vote
0 replies
Comment options

@mikebronner This doesn't seem to be added to the documentation? :)

@backstageel Does it still work for you?

You must be logged in to vote
0 replies
Comment options

I think I removed it again, because I started work on developing an internal solution that wouldn't require more work. Unfortunately I have not been able to complete that at this time due to life circumstances changing A LOT this year.

You must be logged in to vote
0 replies
Comment options

"a custom builder class" not work for me

"message": "Property [localMacros] does not exist on the Eloquent builder instance.",
"exception": "Exception"

You must be logged in to vote
0 replies
Comment options

any update?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Converted from issue

This discussion was converted from issue #275 on March 05, 2025 13:47.

AltStyle によって変換されたページ (->オリジナル) /