seeder-migration-issues

This commit is contained in:
RafficMohammed
2023-01-30 14:23:34 +05:30
parent 4d918c722f
commit 2ec836b447
3628 changed files with 116006 additions and 187 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Seeders;
use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
class AlterColumnTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->modifyStringType(Schema::getAllTables());
}
private function modifyStringType($tables)
{
foreach ($tables as $table) {
$tableName = (array)$table;
$tableName = reset($tableName);
$columns = Schema::getColumnListing($tableName);
foreach ($columns as $column) {
if (Schema::getColumnType($tableName, $column) == 'string') {
Schema::table($tableName, function ($table) use($column) {
$table->string($column)->nullable()->change();
});
} elseif (Schema::getColumnType($tableName, $column) == 'boolean') {
Schema::table($tableName, function ($table) use($column) {
$table->boolean($column)->default(0)->change();
});
}
}
}
}
}