/** * To Perform migration to ensure the table and its properties * are up-to-date * */ public static function migration() { $tables = Migration::tables(); // Simple Filters. if (!isset($tables)) { return false; } foreach ($tables as $key => $value) { if (empty($value) || is_null($value) || !isset($value)) { continue; } loop: if (Capsule::Schema()->hasTable($key)) { foreach ($value as $column => $datatype) { if (!Capsule::Schema()->hasColumn($key, $column)) { //Assign the Name and Datatype for temporary access self::$columns['name'] = $column; self::$columns['datatype'] = $datatype; Capsule::Schema()->table($key, function ($table) { $column = self::$columns['name']; $datatype = self::$columns['datatype']; $table->{$datatype}($column)->after('id'); }); } } } else { Capsule::schema()->create($key, function ($table) { $table->increments('id'); $table->timestamps(); }); goto loop; } } }
public function migrateTable() { DB::Schema()->create('tests', function ($table) { $table->increments('id'); $table->string('title'); $table->integer('seq'); $table->boolean('flag')->nullable(); $table->timestamps(); }); }