nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

"Origin HasMedia model not found"

Open apepindev opened this issue 4 years ago • 5 comments

I followed the guide on adding media using the advanced-nova-media-library package and I'm having an issue. The resource with the custom layout is working fine saving and retrieving images. The issue is trying to get the images back from it to render on my page. Every time I call getMedia() on the layout instance in my viewI get an exception saying "Origin HasMedia model not found". What I did was;

  • Implemented Spatie\MediaLibrary\HasMedia\HasMedia interface and Whitecube\NovaFlexibleContent\Concerns\HasFlexible trait to my Article model.
  • Implemented Spatie\MediaLibrary\HasMedia\HasMedia interface and Whitecube\NovaFlexibleContent\Concerns\HasMediaLibrary trait to my custom SingleImage Flexible Layout class.

My Article model also has this...

public function getFlexibleContentAttribute()
{
    return $this->flexible('content', [
        'image' => SingleImage::class
    ]);
}

So the getMedia() method is in the layout class but for some reason Flexible::getOriginModel() in the trait just returns null, therefore giving the exception. I fear I'm missing something trivial here.

I should also mention I'm using 0.2.0 as later versions require a newer version of advanced-nova-media-library and that then requires spatie/laravel-medialibrary v8 that requires php 7.4+ where I'm currently on 7.2. Upgrading php isn't ideal right now but if it's the only option then I'll probably have to.

apepindev avatar Jun 14 '20 21:06 apepindev