Skip to content

Trait method newEloquentBuilder has not been applied, because there are collisions with other trait methods #137

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
eelco2k opened this issue Jun 1, 2018 · 15 comments

Comments

@eelco2k
Copy link

eelco2k commented Jun 1, 2018

Issue

Trait method newEloquentBuilder has not been applied, because there are collisions with other trait methods on App\Models\Flight.

I found out that i'm also using \Grimzy\LaravelMysqlSpatial Trait in this model.
and reading this issue it looks like it has to do with this package.
grimzy/laravel-mysql-spatial#17

I'm not sure if it's possible to implement a method to fix this issue in this package or that i do have to create my own custom "Illuminate\Database\Eloquent\Builder".

Environment

Laravel Version: 5.5.40
Laravel Model Caching Package Version: 0.2.62
PHP Version: PHP 7.1.8

Operating System & Version: Mac OS X

Stack Trace


(1/1) FatalErrorExceptionTrait method newEloquentBuilder has not been applied, because there are collisions with other trait methods on App\Models\Flight
--
@mikebronner mikebronner self-assigned this Jun 3, 2018
@mikebronner
Copy link
Owner

Hi @eelco2k, off the top of my head, I believe this is something you will have to resolve locally in your app. Please let me know if you do find a solution, so I can take a look and see if it would be possible to implement in the package.

@eelco2k
Copy link
Author

eelco2k commented Jun 4, 2018

as @grimzy commented out in this issue: grimzy/laravel-mysql-spatial#17 he wrote a custom Illuminate\Database\Eloquent\Builder and extending own packages classes with a Trait.

Perhaps this would be a good method to do as well for laravel-model-caching.

@eelco2k
Copy link
Author

eelco2k commented Jun 5, 2018

i've tried to move the functions in CachedBuilder.php into a Trait but this didn't work sadly.

I've also tried this in conjuction with the dev-builder-as-trait branch of the grimzy/laravel-mysql-spatial but i'm still getting the same errors.

So no solution yet.

@mikebronner
Copy link
Owner

Yea, I don't think there is an easy solution for this at this time. I'm closing this for now. Please re-open if you have further information that may help out. Thanks for looking into it!

@Spodnet
Copy link

Spodnet commented Aug 4, 2018

I had this problem with \Kalnoy\Nestedset\NodeTrait

I think this is working as a simple solution in my case, the node trait ran

public function newEloquentBuilder($query) {
    return new QueryBuilder($query);
}

Looking at the code in the model caching, it was ok to simply override in my model

use \GeneaLabs\LaravelModelCaching\Traits\Cachable {
        \GeneaLabs\LaravelModelCaching\Traits\Cachable::newEloquentBuilder insteadof \Kalnoy\Nestedset\NodeTrait;
}

I would imagine providing the trait that's causing issues doesn't do anything that would cause issues overriding might solve it. Otherwise you'll need to write your own trait to handle the conflict cases I would think.

I'm still testing for any side effects...

@Daniyal-Javani
Copy link

I had this problem with \Kalnoy\Nestedset\NodeTrait

I think this is working as a simple solution in my case, the node trait ran

public function newEloquentBuilder($query) {
    return new QueryBuilder($query);
}

Looking at the code in the model caching, it was ok to simply override in my model

use \GeneaLabs\LaravelModelCaching\Traits\Cachable {
        \GeneaLabs\LaravelModelCaching\Traits\Cachable::newEloquentBuilder insteadof \Kalnoy\Nestedset\NodeTrait;
}

I would imagine providing the trait that's causing issues doesn't do anything that would cause issues overriding might solve it. Otherwise you'll need to write your own trait to handle the conflict cases I would think.

I'm still testing for any side effects...

@Spodnet Have you found any side effects?

@Spodnet
Copy link

Spodnet commented Oct 16, 2018

No issues so far :)

@indowebdeveloper
Copy link

I've tried @Spodnet solution above, and found that you will be no longer able to use any of \Kalnoy\Nestedset\NodeTrait method, for example, withDepth will no longer be able to use...

@LiamAird
Copy link

LiamAird commented Sep 1, 2020

This is still an issue - is there any workaround, now nearly two years later?

@mikebronner
Copy link
Owner

@LiamAird Please open a new issue with full stack trace and query and all the version information.

@mikebronner
Copy link
Owner

@Spodnet @indowebdeveloper @Daniyal-Javani @eelco2k Could you give release 0.10.2 a try and let me know if that fixes the issue? Please see the readme section towards the top regarding conflicting packages as how to implement it. Thanks!

@LiamAird
Copy link

LiamAird commented Sep 7, 2020

I tried implementing the fix, but get the error:
Call to undefined method GeneaLabs\LaravelModelCaching\ModelCaching::useBuilder()

use GeneaLabs\LaravelModelCaching\ModelCaching;
use Kalnoy\Nestedset\QueryBuilder;

class AppServiceProvider extends ServiceProvider
{

    public function register()
    {
        //
    }
 
    public function boot()
    {
         ModelCaching::useBuilder(QueryBuilder::class);
    }

@mikebronner
Copy link
Owner

Can you make sure you got the latest update, change your composer json to

"genealabs/laravel-model-caching":"^0.10.2",

then run composer update again.

@LiamAird
Copy link

LiamAird commented Sep 8, 2020

@mikebronner Its already at that version.
image

@mikebronner
Copy link
Owner

Hmmm, ok. Leave it at release 0.10.1 for now, I'm working on an update to this functionality and hope to release it in the next day or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants