如何获取数据库字段类型在Laravel? [英] How to get database field type in Laravel?
问题描述
有没有办法获取数据库表字段的数据类型?
几乎像迁移的逆。
例如,如果用户表列的迁移看起来像
...
$ table-> integer('age')
...
如果我指定table user
和列 age
?
我不感兴趣的特定数据库实现,
mysql_field_type()
)。就像Laravel的迁移,它需要是数据库不可知的。在Laravel挖掘之后,这是我得到的。 >
DB :: connection() - > getDoctrineColumn('users','age') - > getType() - > getName / code>
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
...
$table->integer('age')
...
Is there a function that will return integer
if I specify table user
and column age
?
I'm not interested in a specific database implementation, (mysql_field_type()
). Like Laravel's migration, it needs to be database agnostic.
After digging in Laravel, this is what I got.
DB::connection()->getDoctrineColumn('users', 'age')->getType()->getName()
这篇关于如何获取数据库字段类型在Laravel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!