How to use a unique validator in several models


You see, I have 2 models, called Type and Category. Both have as unique variable a string called name. To handle your forms, I have this validator:

public function rules(){

With this I can assure in both forms that the value is not null, but there is a problem, that I also want in both models that the value is unique. To indicate that a value is unique, unique is used, but generally it requires to indicate in which table the verification will be done, which would force me to duplicate it. Is there any way to have it checked in 2 tables, giving an error if it appeared in any of the 2?

That is, normally what you would have to do is for the Table Type unique:tipos and for Category unique:categorias . Is there a way to check both at the same time?

asked by Miguel Alparez 29.11.2018 в 11:09

0 answers