Yii2 Unique Validation not working for combination of employee id and company id Below are my model code.
public function rules()
{
return [
[['company_id', 'role_id'], 'required'],
[['company_id', 'role_id', 'status'], 'integer'],
[['employee_id'], 'string', 'max' => 15],
[['report_to'], 'string', 'max' => 16],
[['id',],'safe'],
['employee_id', 'unique', 'targetAttribute' => ['company_id', 'employee_id'], 'message' => 'The combination of Company ID and Employee ID has already been taken.']
// ['employee_id', 'unique', 'targetAttribute' => ['company_id'], 'message' => 'The combination of Company ID and Employee ID has already been taken.']
];
}'
And this my controller code
$model = new Employee();
//$profile = new Profile();
// $profile->scenario = 'emp_bulk_uplscenariooad';
if($model->load(Yii::$app->request->post())) {
$model->company_id = $userModel->company_id;
$model->employee_id = Yii::$app->request->post()['Employee']['employee_id'];
$model->role_id = Yii::$app->request->post()['Employee']['role_id'];
$model->report_to = Yii::$app->request->post()['Employee']['report_to'];
// print_r(!$model->validate());die();
if($model->save(false)){
}
*************************************************************************
please help me with this.thanks in advance