laravel/framework — pull request #4890 by FractalizeR (2014-06-29 11:49:15+00:00)
Title: Custom Column Type in Schema Builder - centralized way to handle

This is an implementation of custom column types in Schema Builder mentioned in #3393, #678, #376.

Implementation is alternative to #4885 and provides a universal way to handle new custom types in database.

First we register column type:
```php
Schema::registerCustomType('my_custom_type', [
'MySql' => function ($param1, $param2) {
return sprintf('MY_MYSQL_TYPE (%s, %s)', $param1, $param2);
},
'Postgres' => function ($param1, $param2) {
return sprintf('MY_POSTGRES_TYPE (%s ||| %s)', $param1, $param2);
},
]);
```
Keys 'MySql' and 'Postres' are the string endings of Schema grammar class names. If grammar class name ends with 'Grammar', 'Grammar' is trimmed before comparison.Grammar class hierarchy is respected.

Custom column type is then added to the table by calling blueprint's ```custom()``` method

```php
Schema::create('user', function (Blueprint $table) {
$table->custom('my_col', 'my_custom_type', 'param1', 'param2');
}
```

The generated SQL statement, executed against MySQL connection will look like:

```sql
alter table `user` add `my_col` MY_MYSQL_TYPE (param1, param2) not null
```
whereas if we execute it against Postgres grammar, it will change to:
```sql
alter table `user` add `my_col` MY_POSTGRES_TYPE (param1 ||| param2) not null
```