I am trying to make migration in laravel and I have this condition where a value to be inserted can be either of a number of values from a list, but nothing else outside it. For instance, I have an attribute in database named values
and the actual value of the values
can either be ['one','two','three']
but nothing else. How can I do it using migration builder in Laravel?
Asked
Active
Viewed 46 times
0

Aashan Ghimire
- 5
- 1
- 4
-
As an alternative, you can use validations within the Eloquent model. This way if you need to be able to add options to the column, you only have to update the code and not modify the database. – aynber Jul 09 '18 at 13:45
-
I will definitely do that. I was just curious if I could do it in the database level. If you know what I mean :v – Aashan Ghimire Jul 09 '18 at 13:48
-
The enum that J. Doe mentioned below is a definite option on the database side, but that's usually best if you know the options will never change or if it's going to stay a small table. If it's a table that will have a lot of rows, such as a users or orders table, modifying it later to add options is not a good idea as it will lock up the table as it's modified. – aynber Jul 09 '18 at 13:53