What is the MySQL datatype SET equivalent in Laravel Schema?

前端 未结 6 1846
春和景丽
春和景丽 2020-12-15 10:13

Laravel Schema has a command for ENUM equivalent to the table. What is the SET equivalent to the table?

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 11:13

    Roman Nazarkin's method works almost perfectly however there is a small issue with table prefixes (which this method does not account for) it is simple however to make this suggestion work with table prefixes:

    $grammar = DB::connection()->withTablePrefix(new ExtendedMySqlGrammar());
    // set new grammar class
    DB::connection()->setSchemaGrammar($grammar);
    
    // 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);
    });
    

提交回复
热议问题