我想当我想到这个的时候,我是个代码盲——你知道吗,当你看不到简单的解决方案的过于复杂的时候?!由于@JonasStaudenmeir,心态和重构发生了细微的变化,我的解决方案如下-
我的迁移-
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Searchable::migrateUp('assets', 'moderated');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Searchable::migrateDown('assets');
}
/**
* Creates searchable column on model table
*
* @param string $table Table name to perform migration on
* @param string|null $after Whether to add after a particular column
*
* @return void
*/
public function migrateUp($table, $after = null)
{
// add to our schema
Schema::table(
$table,
function (Blueprint $table) use ($after) {
$table->longText($this->_searchableColumnKey)
->after($after)->nullable();
}
);
// create our index
\DB::statement("ALTER TABLE {$table} ADD FULLTEXT fulltext_searchable ({$this->_searchableColumnKey})");
}
/**
* Removes searchable column on table
*
* @param Blueprint $table Requires blueprint
*
* @return void
*/
public function migrateDown($table)
{
Schema::table(
$table,
function (Blueprint $table) {
$table->dropColumn($this->_searchableColumnKey);
}
);
}
因此,我的方法不是由Schema调用的,而是从方法内部运行Schema!