In Laravel 3 (I don't know how Laravel 4 handles it) you can choose what class to use from an alias. So if you can do this in Laravel 4, you just need to create your own class and make it extend MySqlGrammar.
Yes I found the solution for L3 but not for L4.
Waiting to find the solution I extended the Builder to achieve a similar result.
I've come come across the same issue. I'd like to extend the db Grammars as well as the different Connection methods (eg MySqlConnection).
thujohn, Were you able to find a solution?
My solution was extending the Builder and Model but no really good solution.
I was able to extend both the Blueprint
and the MySqlGrammar
classes, then implement them in my migrations using the following technique:
public function up()
{
DB::connection()->setSchemaGrammar(new MySqlExtendedGrammar());
$schema = DB::connection()->getSchemaBuilder();
$schema->blueprintResolver(function($table, $callback) {
return new ExtendedBlueprint($table, $callback);
});
$schema->create('table', function(ExtendedBlueprint $table) {
// bla bla bla
});
}
benharold said:
I was able to extend both the
Blueprint
and theMySqlGrammar
classes, then implement them in my migrations using the following technique:public function up() { DB::connection()->setSchemaGrammar(new MySqlExtendedGrammar());
$schema = DB::connection()->getSchemaBuilder(); $schema->blueprintResolver(function($table, $callback) { return new ExtendedBlueprint($table, $callback); }); $schema->create('table', function(ExtendedBlueprint $table) { // bla bla bla });
}
This method appears on the face of it to work fine, however if your database has a prefix set in the database config, this method will not automatically prefix tables, so you need to remember to manually fetch the prefix using
$prefix = DB::connection()->getTablePrefix();
You then need to manually prepend the prefix wherever you are using your new table.
There must be an easier way to honor the prefix setting, perhaps by including this extended code somewhere else in the laravel startup, but where exactly i cannot say.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community