Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Validation Rules Don't Work #238

Open
mdavis1982 opened this issue Nov 12, 2020 · 5 comments
Open

Image Validation Rules Don't Work #238

mdavis1982 opened this issue Nov 12, 2020 · 5 comments

Comments

@mdavis1982
Copy link

mdavis1982 commented Nov 12, 2020

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
Copy link
Author

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

@NioTeX
Copy link

NioTeX commented Apr 7, 2021

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

@mdavis1982
Copy link
Author

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

@mateusgalasso
Copy link

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

@toonvandenbos
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants