Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Writing dynamic validation rules when saving a model

0
by xyz.qtc, last modified on December 21st, 2023
public function beforeSave()
    {
                $rules = [
                        'amount_picked' => 'numeric|min:0|max:' . $this->amount_required
                ];

                    \Validator::make($this->toArray(), $rules)->validate();
    }
public function beforeValidate()
    {
                $this->rules['amount_picked'] = 'numeric|min:0|max:' . $this->amount_required;
    }

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?