<?php namespace Concore\Foundation\Models\Traits;

use DB;

trait HasEnumTrait {

	public function getEnumValues($column) {
		$table = $this->getTable();
		$type = DB::select( DB::raw("SHOW COLUMNS FROM $table WHERE Field = '$column'") )[0]->Type;
		preg_match('/^enum\((.*)\)$/', $type, $matches);
		$enum = array();
		foreach(explode(',', $matches[1]) as $value) {
			$v = trim( $value, "'" );
			$enum = array_add($enum, $v, $v);
		}
		return $enum;
	}

}