Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active January 5, 2021 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrobinsonc/ecfc2a33ccb47a7e6ed930edc8192aeb to your computer and use it in GitHub Desktop.
Save jrobinsonc/ecfc2a33ccb47a7e6ed930edc8192aeb to your computer and use it in GitHub Desktop.
Simplifies the job of changing the values of a ENUM field. #laravel
<?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