@murtaza1904 What was the issue with the example at the bottom of your post?
Nov 21, 2023
5
Level 2
How can I use enum class in migration
I have a program day column in the table which has enum type. Right now I define the allows value of enum column like this
$table->enum('program_day',['monday','tuesday','wednesday','thursday','friday','saturday','sunday']);
I do have an enum class which already contain these cases. Enum class
enum DayEnum: string
{
case MONDAY = 'monday';
case TUESDAY = 'tuesday';
case WEDNESDAY = 'wednesday';
case THURSDAY = 'thursday';
case FRIDAY = 'friday';
case SATURDAY = 'saturday';
case SUNDAY = 'sunday';
}
How can I use this class to be define in migration class something like this
$table->enum('program_day', \App\Enums\DayEnum::cases());
Level 2
@martinbean The method returns array of an object of enum class and I found the solution for it.
array_column(DayEnum::cases(), 'value')
I achieve the functionality using above code but if there is a better way of doing that?
Please or to participate in this conversation.