title: How to Use unique rules in active record yii2
body: <p>I want to set the values of my table column set as unique value, how i can use to set error if in insert form, I insert the same value as data in my database?
  <br/><br/>
  Is it true?</p>
  
  <pre><code>    public function rules()
  {
      return [
          [['nama_barang', 'harga', 'stok', 'id_satuan'], 'required'],
          [['harga', 'stok', 'id_satuan'], 'integer'],
          ['nama_barang', 'unique', 'targetAttribute' =&gt; ['nama_barang' =&gt; 'nama_barang']],
          [['foto'], 'safe']
      ];
  }
  </code></pre>