Closed zannix closed 5 years ago
@zannix Thanks for reporting! Can you provide your complete stack trace for this error, as well as the eloquent query you are are running. I will try to reproduce. Better yet, if you have a public repo that already reproduces this issue, please link it here so I can investigate. :) Thanks!
The issue was caused upon trying to instantiate and save a new model inside a static method of the model class by calling $model = new self(); .... $model->save();
Here is the full stack trace:
This is likely an issue with the laravel-pivot package, as model-caching does not fire events. See the following discussions: https://github.com/laravel/telescope/issues/187 https://github.com/fico7489/laravel-pivot/pull/50
I believe this should be resolved once laravel-pivot 4.0 is released (no date on that though).
I'm going to throw my 2 cents in here. There is some kind of interaction that is happening between this plugin and that one that triggers these kinds of errors.
I say that because I am in the process of trying to add your auto-caching to my, relatively new, repo. When I make the call to my API endpoint without implementing model caching it returns just fine as is. HOWEVER, as soon as I add the Cacheable trait from this plugin it barfs with the following output.
Call to undefined method Illuminate\Events\Dispatcher::fire()
I'm doing this through Postman, pardon the broken error listing. It refers to this file "var/www/vendor/fico7489/laravel-pivot/src/Traits/ExtendFireModelEventTrait.php" on line 36
It also outputs this code segment: ` if (!isset(static::$dispatcher)) { return true; }
// First, we will get the proper method to call on the event dispatcher, and then we
// will attempt to fire a custom, object based event for the given event. If that
// returns a result we can return that result, or we'll call the string events.
$method = $halt ? 'until' : 'fire';
$result = $this->filterModelEventResults(
$this->fireCustomModelEvent($event, $method)
);
if (false === $result) {
return false;
}
$payload = ['model' => $this, 'relation' => $relationName, 'pivotIds' => $ids, 'pivotIdsAttributes' => $idsAttributes];
return !empty($result) ? $result : static::$dispatcher->{$method}(
"eloquent.{$event}: ".static::class, $payload
);
}
} `
This is on my local env running via Docksal. I upgraded to Laravel 5.8. Got v0.4.7 of this package, etc.
Somehow these two do not play nicely together. I will report back when I find more out.
@pthurmond Please see this issue: https://github.com/GeneaLabs/laravel-model-caching/issues/219
Upon installing Laravel Telescope package, there seems to be an issue that's being caused by the incompatibility with laravel-model-caching.
The issue is also commented here: https://github.com/laravel/telescope/issues/187
ErrorException thrown with message "Undefined offset: 0" in /vendor/laravel/telescope/src/Watchers/ModelWatcher.php:35
When laravel-model-caching is disabled, everything operates normally.