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 field rules dont applied in dependency container #19

Open
ahmadmhm opened this issue Nov 27, 2022 · 3 comments
Open

Image field rules dont applied in dependency container #19

ahmadmhm opened this issue Nov 27, 2022 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@ahmadmhm
Copy link

When I set rules to Image field in dependency container it doesnt apply on uploading images. Below is the exact code.

DependencyContainer::make([
                Image::make(__('Insurance Image'), 'image')
                    ->rules(['required', 'image','mimes:jpg,jpeg,png', 'max:2000'])
                    ->path('images/loads-insurance'),
            ])

In this situation every file uploaded and rules ignored.

@alexwenzel
Copy link
Owner

hi @ahmadmhm

this code works for me. i will publish y new version in some minutes.

image

@alexwenzel alexwenzel added question Further information is requested help wanted Extra attention is needed and removed question Further information is requested labels Feb 20, 2023
@ahmadmhm
Copy link
Author

Ok, Thank you

@Paulsky
Copy link

Paulsky commented Jan 30, 2024

I think this issue is still open right? This is my workarroud:

Create an Hidden dummyfield, which can trigger a custom validation in the Request

DependencyContainer::make([
    Image::make(__('Insurance Image'), 'insurance_image'),
    Hidden::make('insurance_image_validator')->fillUsing(function($request, $model, $attribute, $requestAttribute){
        if($request->has('insurance_image')) {        
            $request->validate([
                'insurance_image' => 'required|image|mimes:jpg,jpeg,png|max:2000',
            ]);
        }
        //remove the dummy field from the request
        $request->request->remove('insurance_image_validator');
    }),
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants