-
Notifications
You must be signed in to change notification settings - Fork 232
Doesn't work with Spatie's Laravel QueryBuilder #487
-
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
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 7 comments
-
@backstageel Thanks for submitting your issue. This package will not work with third-party query builders, only with Laravel's query builder. Sorry.
Beta Was this translation helpful? Give feedback.
All reactions
-
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; }
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4
-
I'll add this to the documentation, thanks!
Beta Was this translation helpful? Give feedback.
All reactions
-
@mikebronner This doesn't seem to be added to the documentation? :)
@backstageel Does it still work for you?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
"a custom builder class" not work for me
"message": "Property [localMacros] does not exist on the Eloquent builder instance.",
"exception": "Exception"
Beta Was this translation helpful? Give feedback.
All reactions
-
any update?
Beta Was this translation helpful? Give feedback.