dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
262 stars 62 forks source link

I want when I work to replace the file The old image is saved and a new created. ? #182

Open mostafasamirs opened 1 year ago

mostafasamirs commented 1 year ago

I want when I work to replace the file The old image is saved and a new one is created


my code public static function SingleImage(bool $isRequired, string $mediaCollection, string $name = 'Image', string $helpText = null): Medialibrary { return MediaLibrary::make(__($name), $mediaCollection)->fields(function() { return [ Text::make('File Name', 'file_name') ->rules('required', 'min:2'),

            Text::make('Image Title', 'img_title')
                ->translatable()
                ->rules(RulesHelper::NULLABLE_MID_STRING_VALIDATION),

            Text::make('Image Alt', 'img_alt')
                ->translatable()
                ->rules(RulesHelper::NULLABLE_MID_STRING_VALIDATION)
        ];
    })
    ->attachRules($isRequired ? RulesHelper::REQUIRED_IMAGE_VALIDATION : RulesHelper::NULLABLE_IMAGE_VALIDATION)
    ->accept('image/*')
    ->autouploading()
    ->hideFromIndex()
    ->attachOnDetails()
    ->single()
    ->help($helpText);
}