Laraveldaily\Quickadmin\Builders\ModelBuilder::enum PHP Method

enum() public method

Generate enum model
public enum ( ) : string
return string
    public function enum()
    {
        $return = "\r\n";
        foreach ($this->fields as $field) {
            if ($field->type == 'enum') {
                $values = '';
                $field->enum = explode(',', $field->enum);
                foreach ($field->enum as $val) {
                    // Remove first whitespace
                    if (strpos(substr($val, 0, 1), ' ') !== false) {
                        $len = strlen($val);
                        $val = substr($val, 1, $len);
                    }
                    $values .= '"' . $val . '" => "' . $val . '"';
                    if ($val != last($field->enum)) {
                        $values .= ', ';
                    }
                }
                $return .= '    public static $' . $field->title . ' = [' . $values . '];' . "\r\n";
            }
        }
        return $return;
    }