I am new to Yii framework, and m stuck in a simple task of checking weather user has supplied any inputs for update request or not.
considering the following code
Model Code:
class Car extends ActiveRecord {
public $id;
public $name;
public $registration;
public $created_at;
public function sceanrios(){
return ['create'=>['name','registration'],
'update'=>['name','registration']];
}
public function rules(){
return [['name','registration'],'required','on'=>'create']
}
}
Controller:
class CarController extends yii\rest\ActiveController{
public $modelClass = 'models/Car';
}
When I send PUT request to CarController without posting any attribute, it gives 200 OK response.
I want a validation rule that checks if user has actually posted any value then return OK after updating it; else return error message "Atleast one field should be set to update"
I have found following solution Yii2 dependency custom rule validation that only works for POST request i.e in create scenario, but its not working in update scenario as $this->attribute holds old values.
another solution with same issue Yii form model validation- either one is required that does not work for PUT request
found many others they only work for new record, but not for updating existing record.
Is there any validator for this?