How to refactor common columns in migration in laravel?
I have these columns which I need to use on every migration tables.
$table->string('created_by');
$table->string('updated_by')->nullable();
$table->timestamps();
I need to extract these line, so that I do not have to write them every time. How can I achieve that with laravel 5.2?
trait usedColumns {
public function runColmuns($table)
{
$table->string('created_by'); $table->string('updated_by')->nullable(); $table->timestamps();
}
}
EDIT : $table should be passed
and in your migration's class, use the trait and run the method
$this->runColmuns($table);
Thanks. It works after I passed the $table to the function.
Please or to participate in this conversation.