How to get database field type in Laravel?

后端 未结 9 2087
离开以前
离开以前 2020-12-14 01:38

Is there a way to get the datatype of a database table field? Almost like a inverse of migration.

For example, if the migration of a users table column looks like

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 02:18

    I use this with laravel 4.1,,

    $schema = \DB::getDoctrineSchemaManager();
    $tables = $schema->listTables();
    
    foreach ($tables as $table) {
        echo "".$table->getName() . " columns:
    "; foreach ($table->getColumns() as $column) { echo ' - ' . $column->getName() . " - " . $column->getType()->getName() . "
    "; } }

    or to get specific table use this: $columns = $schema->listTableColumns('user');

提交回复
热议问题