nova-flexible-content
nova-flexible-content copied to clipboard
Image Validation Rules Don't Work
Laravel Version: 8.13.0 Nova Version: 3.14.0 Flexible Content Version: 0.2.6
When trying to validate an image, I can't get the validation rules to work. For example, when doing the following:
<?php
namespace App\Nova\Flexible\Layouts;
use Laravel\Nova\Fields\Image;
use Whitecube\NovaFlexibleContent\Layouts\Layout;
class ImageLayout extends Layout
{
/** @var string */
protected $name = 'image';
/** @var string */
protected $title = 'Image';
public function fields()
{
return [
Image::make('Image')
->rules('required', 'image', 'mimes:jpg,jpeg', 'max:512')
->help('The image'),
];
}
}
Both the image and mimes validation rule fail, even when uploading a valid image. It also seems as though the max validation rule isn't being applied to the image file itself.
@Nyratas Would it be possible to take a look at this please? 😄
@mdavis1982 Did you find a solution for this by any chance?
@NioTeX I didn't. In the end we moved to a different platform and used that headless. Which was a pain because this does exactly what we need, but we couldn't trust our users to not add invalid images 😄
I'd love to dig into this to get it working, but I just don't have the time at the moment.
I don't know if it will help but in my case, I did the following
- I created a custom validation request
and I put the rule as follows
public function passes($attribute, $value)
{
//Check if file is PDF
return Request::file($value)->getMimeType() === 'application/pdf';
}
A few changes have been released in v1.0.8 thanks to @michaelbaril's PR (#310). Could someone please confirm that all cases covered by this issue have been solved? Thanks.