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

node.js - How to mock a third-party api calls in the backend -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -