Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
backstageel opened this issue Jul 24, 2019 · 7 comments
Closed

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

backstageel opened this issue Jul 24, 2019 · 7 comments
Assignees

Comments

@backstageel
Copy link

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
@mikebronner
Copy link
Owner

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

@backstageel
Copy link
Author

backstageel commented Aug 1, 2019

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;
}

@mikebronner
Copy link
Owner

I'll add this to the documentation, thanks!

@mikebronner mikebronner reopened this Aug 11, 2019
@mikebronner mikebronner self-assigned this Aug 11, 2019
@stale stale bot added the wontfix label Sep 10, 2019
Repository owner deleted a comment from stale bot Sep 10, 2019
@stale stale bot removed the wontfix label Sep 10, 2019
@francoism90
Copy link

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

@backstageel Does it still work for you?

@mikebronner
Copy link
Owner

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.

@seek-x2y
Copy link

seek-x2y commented Sep 3, 2021

"a custom builder class" not work for me

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

@PitchRE
Copy link

PitchRE commented Jan 21, 2022

any update?

Repository owner locked and limited conversation to collaborators Mar 5, 2025
@mikebronner mikebronner converted this issue into discussion #487 Mar 5, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

5 participants