Setting rules dinamically in a livewire component

protected $rules = [
// (other rules)...
'image' => 'nullable|image|max:4096', // now i have this line, but the 4096 must be dynamic
// 'nullable|image|max:' . getDefaultFileMaxSize(), <-- won't work here, how to make it work?
];
protected $rules = [
// (other rules)...
'image' => 'nullable|image|max:4096', // now i have this line, but the 4096 must be dynamic
// 'nullable|image|max:' . getDefaultFileMaxSize(), <-- won't work here, how to make it work?
];
i also tried to set the rules inside the mount method, but doesn't work neither, it ignores it.
9 Replies
toeknee
toeknee7mo ago
You can't change them in the rules set of a protected property with Livewire once the component has booted. You could set them within the rules config of the option
ericmp #2
ericmp #27mo ago
okay hmm im trying to understand wdym by "You could set them within the rules config of the option"?
toeknee
toeknee7mo ago
Can you clarify what the component is doing so we are on the right page
ericmp #2
ericmp #27mo ago
im storing an image relating it to a model. i want that image to be validated -> max:$dynamicValue idk what more to tell u that is it what should i explain?
toeknee
toeknee7mo ago
Can you provide the full code? With our file uploader field we have ->rules() and this accepts a closure so you can do checks etc on that level.
ericmp #2
ericmp #27mo ago
im not using filament (see tag)
toeknee
toeknee7mo ago
I was under the assumption it was a custom livewire component for a filamenet form
toeknee
toeknee7mo ago
under the livewire discussions: https://github.com/livewire/livewire/discussions/2569 If it's a custom livewire component completely and use hydration
GitHub
Dynamic rules for property binding · livewire livewire · Discussion...
I am building a Livewire component that I intend to use dynamically with different models. It will simply display a table with all records of a certain models, with buttons to delete and edit. My a...
ericmp #2
ericmp #27mo ago
oh i see, so i have to move it from mounted to render method thanks for the help, im going to try it now, lets see