Step 1. Extending the classes by default (add this code to the migration file after use ):
class ExtendedBlueprint extends Blueprint { public function set($column, array $allowed) { return $this->addColumn('set', $column, compact('allowed')); } } class ExtendedMySqlGrammar extends Illuminate\Database\Schema\Grammars\MySqlGrammar { protected function typeSet(\Illuminate\Support\Fluent $column) { return "set('".implode("', '", $column->allowed)."')"; } }
Step 2 .. Then we need to change the default grammar classes and classes:
// set new grammar class DB::connection()->setSchemaGrammar(new ExtendedMySqlGrammar()); // get custom schema object $schema = DB::connection()->getSchemaBuilder(); // bind new blueprint class $schema->blueprintResolver(function($table, $callback) { return new ExtendedBlueprint($table, $callback); }); // then create tables $schema->create('table name', function(ExtendedBlueprint $table) { $table->increments('id'); $table->text('sentence'); $table->string('author')->nullable(); $table->string('source')->nullable(); $table->set('difficulty', range(1, 10)); // use our new mysql type $table->boolean('enabled')->default(true); });
This method will also work after composer update , because we have not edited any frame code.
Roman nazarkin
source share