如何获取数据库字段类型在Laravel? [英] How to get database field type in Laravel?

查看:865
本文介绍了如何获取数据库字段类型在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆