ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
597 stars 297 forks source link

There was a problem submitting the form when insert new image in my resource #334

Open ghoreyshi opened 2 years ago

ghoreyshi commented 2 years ago

Hello, I use advance-nova-media-library for upload image but after submite form, show error

![Uploading 2022-06-14 00.02.58.jpg…]()

App\Models\File.php


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class File extends Model implements HasMedia
{
    use HasFactory, InteractsWithMedia;

    public $fillable = [
        'file',
        'size',
        'format'
    ];

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb');
    }

    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('file');
    }
}

App\Nova\File.php


use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Avatar;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class File extends Resource
{

     /**
     * Get the fields displayed by the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('format'),
            Number::make('size'),
            Images::make('file', 'file'),
        ];
    }
}
benedict-w commented 2 years ago

I also get this error "There was a problem submitting the form" with a Nova 4 resource with multiple images:

Images::make('Images'),

In my case I think it's related to the media conversion:

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('image')
            ->width(500)
            ->height(500);
    }

If I remove this code the upload works...

Otherwise the Nova resource AJAX request is returning a 500 empty response:

?viaResource=&viaResourceId=&viaRelationship=&editing=true&editMode=update

I've tried debugging but no errors appearing in logs.

Any ideas?

benedict-w commented 2 years ago

In my case the issue was GD failing silently. It turns out I needed to increase the PHP memory_limit for it to work!

abrahamarslan commented 1 year ago

What's the issue here?