Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

r.mihnea's avatar

Laravel Advanced Nova Media Library

Hi! I'm trying to use the Advanced Nova Media Library for a project and I'm having difficulties with uploading photos. Even though a image is uploaded, be it jpg or png, I get a validation error: "Field image must be an image".

The model code looks like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\Models\Media;

class Prize extends Model implements HasMedia
{
    use HasMediaTrait;

    public function registerMediaConversions(Media $media = null)
    {
        $this->addMediaConversion('thumb')
            ->width(130)
            ->height(130);

        $this->addMediaConversion('original');
    }

    public function registerMediaCollections()
    {
        $this->addMediaCollection('image')
             ->singleFile();
    }
	...
}

And the Nova Model as follows:

class Prize extends Resource
{
	...
	public function fields(Request $request)
    {
        return [
            ...
            Images::make(__('Fields.Image'), 'image') 
            ->conversionOnPreview('original') 
            ->conversionOnDetailView('thumb')
            ->conversionOnIndexView('thumb')
            ->conversionOnForm('thumb')
            ->fullSize()
            //->rules('nullable', 'image', 'mimes:jpg,png,jpeg')
            //->creationRules('nullable', 'image', 'mimes:jpg,png,jpeg')
            //->updateRules('nullable')
            ->singleImageRules('nullable','dimensions:min_width=100'),
            ...
        ];
    }

As seen in the above code, I tried using the creationRules() and updateRules() methods as suggested in some similar problems I found online. However, none of them worked, I honestly have no idea why this error is popping up.

Thank you in advance for any help given!

0 likes
0 replies

Please or to participate in this conversation.