I have a form which takes various charges on daily basis for patients in hospital. I want to limit one entry for any patient for a specific charge(service charge) in one day.
How can I create a validation like this.
I am looking for some direction to create such a rule.
Assume that the name of the active record class is StudentLog.
public function rules()
{
return [
['log_date','date'],
['log_date','validateOnlyOne'],
];
}
public function validateOnlyOne($attribute, $params)
{
$st = StudentLog::find()->where(['log_date' => $this->log_date])->one();
if(asset($st)
$this->adError('Can only have one record per day');
}