mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.26k stars 217 forks source link

Doesn't get any attributes casts with Nova #233

Closed d8vjork closed 5 years ago

d8vjork commented 5 years ago

Describe the bug When using Laravel Nova it doesn't get any of the casts and on Date fields is always returning an error because of that (must always cast to dates to work).

Eloquent Query Nothing (Nova's internal)...

Stack Trace

Environment

Additional context I don't include much information because I think is simple, don't know if is any solution to this

d8vjork commented 5 years ago

Ok, only works with accessors :/ it will be fantastic if we've casts available for this

Edit: Nothing on casts work, so all needs to be manually cast using accessors

mikebronner commented 5 years ago

@d8vjork Can you elaborate a bit more? Is there a stack trace? I don't think I understand what the problem is. Can you provide specific steps to reproduce?

d8vjork commented 5 years ago

@mikebronner Of course, now with the edit I got more stuff to show, let's explain this:

One of the issues is using casts to arrays (using fourstacks/nova-repeatable-fields package with Nova and Telescope) and trying to save the model I've got an Undefined offset: 0, so this is related with #226 laravel/telescope#187 (Stacktrace: https://gist.github.com/d8vjork/14f721e327b30041fa49356c90d02c77)

I know this one is not related to Model caching, but this other yes:

Date field must cast to 'date' in Eloquent model. (Stacktrace & details: https://gist.github.com/d8vjork/411a7cdb9a5bad79e6d85a0448b84a9e)

Temporary fixed with this (but still don't get anything from casts even cleaning all the cache)

    protected $casts = [
        // 'released' => 'date',
    ];

    public function getReleasedAttribute($value)
    {
        return new Carbon($value);
    }
mikebronner commented 5 years ago

@d8vjork Could you post the code for your model, as well as the Nova resource class for the model? That might help me figure out what's going on. Thanks!

mikebronner commented 5 years ago

Closing due to inactivity. Please re-open when you get a chance to post additional info. Thanks :)