Last active
January 5, 2021 15:13
-
-
Save jrobinsonc/ecfc2a33ccb47a7e6ed930edc8192aeb to your computer and use it in GitHub Desktop.
Simplifies the job of changing the values of a ENUM field. #laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Update enum column | |
* | |
* @param string $tableName Table to update. | |
* @param string $columnName Column to update. | |
* @param array $values Values for ENUM column. | |
* @return void | |
*/ | |
public static function updateEnumField(string $tableName, string $columnName, array $values) | |
{ | |
$enumValues = implode('\',\'', $values); | |
DB::statement("ALTER TABLE $tableName MODIFY COLUMN $columnName ENUM('$enumValues')"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment