Extends Laravel’s Schema/Grammar/Blueprint to describe drivers’ specific features

Extends Laravel’s Schema/Grammar/Blueprint to describe drivers’ specific features

README

Extends Laravel’s Schema/Grammar/Blueprint to describe drivers’ specific features.

Install

composer require "ooxif/laravel-spec-schema:1.0.*"

then

  • add 'OoxifLaravelSpecSchemaSpecSchemaServiceProvider', to providers in config/app.php.
  • replace 'Schema' => 'IlluminateSupportFacadesSchema', to 'Schema' => 'OoxifLaravelSpecSchemaFacadesSchema', in aliases of config/app.php.

Examples

use OoxifLaravelSpecSchemaBlueprint;

Schema::create('table_name', function (Blueprint $table) {
    // Blueprint extends IlluminateDatabaseSchemaBlueprint.

    // add a BINARY column if the driver is MySQL,
    // otherwise falls back to default binary(). 
    $table->myBinary('column_name', 8);
    
    // VARBINARY/TINYBLOB/MEDIUMBLOB/LONGBLOB also falls back to default binary().
    $table->myVarBinary('column_name', 16);
    $table->myTinyBlob('column_name');
    $table->myMediumBlob('column_name');
    $table->myLongBlob('column_name');
    
    // TINYTEXT falls back to default text().
    $table->myTinyText('column_name');
    
    // add `collate`
    $table->string('column_name')->collate('utf8_bin');
});

Use your own Schema Builder/Grammar/Blueprint classes

class MyMySqlBuilder extends OoxifLaravelSpecSchemaMySqlBuilder
                  // extends IlluminateDatabaseSchemaMySqlBuilder
{
    // your code here.
}

class MyMySqlGrammar extends OoxifLaravelSpecSchemaMySqlGrammar
                  // extends IlluminateDatabaseSchemaGrammarsMySqlGrammar
{
    // your code here.
}

class MyBlueprint extends OoxifLaravelSpecSchemaBlueprint
               // extends IlluminateDatabaseSchemaBlueprint
{
    // your code here.
}


// setBuilderClass(string $driverName, string $className)
Schema::setBuilderClass('mysql', 'MyMySqlBuilder');

// setGrammarClass(string $driverName, string $className)
Schema::setGrammarClass('mysql', 'MyMySqlGrammar');

// setBlueprintClass(string $className)
Schema::setBlueprintClass('MyBlueprint');


Schema::create('table_name', function ($table) {
    $table instanceof MyBlueprint; // true
    
    $table->getBuilder() instanceof MyMySqlBuilder; // true
    
    $table->getBuilder()->getGrammer() instanceof MyMySqlGrammar; // true
});

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *