laravel-model-caching icon indicating copy to clipboard operation
laravel-model-caching copied to clipboard

Saving not working with eloquent strict mode

Open jamesRUS52 opened this issue 2 years ago • 3 comments

When using in app service provider

Model::shouldBeStrict(!$this->app->isProduction());

saving model not working with exception Illuminate \ Database \ Eloquent \ MissingAttributeException The attribute [query] either does not exist or was not retrieved for model [app\Models\MyModel].

Eloquent Query Please provide the complete eloquent query that caused the bug, for example:

$record = MyModel::find($id);
$record->field = 'foo';
$record->save();

Stack Trace Illuminate \ Database \ Eloquent \ MissingAttributeException The attribute [query] either does not exist or was not retrieved for model [app\Models\MyModel].

Environment PHP 8.1.6 Laravel 9.36.3 Model Caching: 0.12.5

** work around ** add to model

protected $query = null; // required property for Cachable trait

I think you should add this in trait

jamesRUS52 avatar Nov 18 '22 11:11 jamesRUS52

up

jamesRUS52 avatar Oct 16 '23 16:10 jamesRUS52

Bump, error is present with newest wersion of laravel and this package.

webard avatar Feb 23 '24 19:02 webard