outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
274 stars 96 forks source link

How do you create rules for settings fields ? #32

Closed ghost closed 3 years ago

ghost commented 3 years ago
VaporImage::make('Featured Backgroud Image', 'ft_number_backgroud_image')
->rules('bail', 'required', function($attribute, $value, $fail) use ($request) {
                        if (Storage::size($request->input('vaporFile')[$attribute]['key']) > 1000) {
                            return $fail('The image should not have more than 1 KB');
                        }
                    }),

NovaServiceProvider.boot() method don't have access of request object.

Tarpsvo commented 3 years ago

Why not? The request can be accessed everywhere, for example via request(). I haven't really used Vapor fields though, so I'm not sure how to handle this specific case.

ghost commented 3 years ago

Thanks @Tarpsvo it is working. I have to change some code as well.

VaporImage::make('Featured Backgroud Image', 'ft_number_backgroud_image')
->rules('bail', 'required', function($attribute, $value, $fail) use ($request) {
                        if (Storage::size(request()->input('vaporFile')['key']) > 1000) {
                            return $fail('The image should not have more than 1 KB');
                        }
                    }),