php - Yii2: Custom Validation on Dates based on two models -


i having 2 models namely patient admission having 2 columns such admission_date , discharge_date , model daily_ward_entry having date field date both models related ipd_patient_id

now want create 1 or 2 validators, can restrict date entry in daily_ward_entry between admission_date , discharge_date

i had @ compare validator, can't make out, how replace value compared attribute model relation.

i have tried following variations, throwing error:

variation one

[$this->discharge_date, 'compare', 'comparevalue' => $this->admission_date,  'operator' => '>='], 

error - unknown property – yii\base\unknownpropertyexception

variation two

['discharge_date', 'compare', 'comparevalue' => 'admission_date', 'operator' => '>='], 

error - discharge date must greater or equal "admission_date". error generated irrespective of date lower or greater

variation three

[strtotime($this->discharge_date), 'compare', 'comparevalue' => strtotime($this->admission_date), 'operator' => '>='], 

error - unknown property – yii\base\unknownpropertyexception

i need direction , help. thanks.

in case have perform custom validation. in custom function model data in post, can data , perform validation.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -