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

Image Validation Rules Don't Work

Open mdavis1982 opened this issue 5 years ago • 5 comments

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.

mdavis1982 avatar Nov 12 '20 12:11 mdavis1982

@Nyratas Would it be possible to take a look at this please? 😄

mdavis1982 avatar Nov 18 '20 14:11 mdavis1982

@mdavis1982 Did you find a solution for this by any chance?

NioTeX avatar Apr 07 '21 08:04 NioTeX

@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.

mdavis1982 avatar Apr 07 '21 08:04 mdavis1982

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';
}

mateusgalasso avatar Aug 13 '21 18:08 mateusgalasso

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.

toonvandenbos avatar Jun 27 '23 13:06 toonvandenbos