mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.25k stars 212 forks source link

Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::type() - Corcel incompatibility? #317

Closed wfsmith closed 4 years ago

wfsmith commented 4 years ago

Describe the bug

Fresh install of LaravelModelCaching. Added the use statements and requested a page from our custom laravel app.

This error occurred:

Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::type() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method GeneaLabs\\LaravelModelCaching\\CachedBuilder::type() at /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50)

I am struggling to find the culprit but my guess is that this package is not compatible with Corcel?

Eloquent Query

There are many in the model I'm testing, but they are all mostly Corcel methods.

return Channel::where('post_name', $taxonomy->term->slug)->first();
return Person::whereIn('id', $author_ids->all())->get()->toArray();

etc

Stack Trace

[2020-03-06 18:38:13] local.ERROR: Call to undefined method GeneaLabs\LaravelModelCaching\CachedBuilder::type() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method GeneaLabs\\LaravelModelCaching\\CachedBuilder::type() at /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50)
[stacktrace]
#0 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(36): Illuminate\\Database\\Eloquent\\Builder::throwBadMethodCallException('type')
#1 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1369): Illuminate\\Database\\Eloquent\\Builder->forwardCallTo(Object(Illuminate\\Database\\Query\\Builder), 'type', Array)
#2 /var/www/api.example.org/vendor/genealabs/laravel-model-caching/src/Traits/Caching.php(22): Illuminate\\Database\\Eloquent\\Builder->__call('type', Array)
#3 /var/www/api.example.org/vendor/jgrossi/corcel/src/Model/Post.php(172): GeneaLabs\\LaravelModelCaching\\CachedBuilder->__call('type', Array)
#4 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1620): Corcel\\Model\\Post->newQuery()
#5 /var/www/api.example.org/vendor/genealabs/laravel-model-caching/src/Traits/Caching.php(22): Illuminate\\Database\\Eloquent\\Model->__call('find', Array)
#6 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1632): App\\Models\\Post->__call('find', Array)
#7 /var/www/api.example.org/app/Http/Controllers/StoryController.php(136): Illuminate\\Database\\Eloquent\\Model::__callStatic('find', Array)
#8 [internal function]: App\\Http\\Controllers\\StoryController->show('553556')
#9 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#10 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('show', Array)
#11 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\StoryController), 'show')
#12 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#13 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\\Routing\\Route->run()
#14 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#15 /var/www/api.example.org/app/Http/Middleware/CookieLess.php(25): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\CookieLess->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#19 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#20 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#21 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#22 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#23 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#24 /var/www/api.example.org/vendor/barryvdh/laravel-cors/src/HandleCors.php(36): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Fruitcake\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#28 /var/www/api.example.org/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#29 /var/www/api.example.org/public/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#30 {main}

Environment

Additional context

We're using Corcel on top of Laravel as it is a headless WordPress setup. I followed just the very basic installation instructions, adding the use declarations and refreshing the app.

mikebronner commented 4 years ago

Are you using global scopes -- it looks like type() might be something like that? At the moment this package does not work with global scopes.

wfsmith commented 4 years ago

Ah, yes I am. I have a scope for filtering only published wordpress posts that is applied on the request. Thank you Mike! Looks like I'll have to rely on model caching for now. Cheers

mikebronner commented 4 years ago

Yea, I use local scopes applied with traits (if used by more than one model) to models. That takes care of the global scope issue for me. :)