/** * Creates a new Truck model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Truck(); if ($model->load(Yii::$app->request->post())) { //Yii::$app->request->post('Truck[license_plate]'); $license_plate = $model->license_plate; $check = $model->find()->where(['license_plate' => $license_plate])->one(); if ($check['license_plate'] != '') { return $this->render('create', ['error' => "ทะเบียนรถนี้มีอยู่ในระบบแล้ว ...!", 'model' => $model]); } else { $model->save(); return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['error' => '', 'model' => $model]); } }