Skip to content

Instantly share code, notes, and snippets.

@Kindari
Last active March 8, 2018 23:39
Show Gist options
  • Save Kindari/9283167 to your computer and use it in GitHub Desktop.
Save Kindari/9283167 to your computer and use it in GitHub Desktop.
<?php namespace Acme\Database;
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
class Blueprint extends BaseBlueprint {}
<?php namespace Acme\Database;
use Illuminate\Database\MysqlConnection as BaseMysqlConnection;
use Illuminate\Database\Schema\MysqlBuilder;
class MysqlConnection extends BaseMysqlConnection
{
/**
* Get a schema builder instance for the connection.
*
* @return \Illuminate\Database\Schema\MySqlBuilder
*/
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); }
return new MySqlBuilder($this)->blueprintResolver(function($table, $callback) {
return Blueprint( $table, $callback ); // return our custom Blueprint class
});
}
/**
* Get the default schema grammar instance.
*
* @return \Illuminate\Database\Schema\Grammars\MySqlGrammar
*/
protected function getDefaultSchemaGrammar()
{
return $this->withTablePrefix(new SchemaGrammar); // return our custom SchemaGrammer
}
}
<?php namespace Acme\Database;
use Illuminate\Database\Schema\Grammars\MySqlGrammar
class SchemaGrammer extends MysqlGrammer
{
}
<?php
// This can (and most likely should) be in a Service Provider
App::bind('db.connection.mysql', 'Acme\Database\MysqlConnection');
@orukaz
Copy link

orukaz commented Mar 2, 2018

I would like to extend my Laravel 5.5 (or 5.6) Blueprint class with custom method. Can you please update this Blueprint extension example, I can't get mine working. Something has changed over time or etc...

Also how to execute that in the migration php file?

@malekbenelouafi
Copy link

i get the same issue here for Laravel 5.6, any update please, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment