Php 使用Laravel模式生成器返回列约束
我可以使用以下命令返回数据库表中的列数组Php 使用Laravel模式生成器返回列约束,php,laravel,laravel-5.1,Php,Laravel,Laravel 5.1,我可以使用以下命令返回数据库表中的列数组 $column_names = DB::getSchemaBuilder()->getColumnListing('tablename'); 但是有没有一种方法可以返回每个特定列上的可接受值?例如,我有许多列是enums,我想返回这些列(可能在多维数组中),这样我就可以在单元测试中使用它。getDoctrineColumn就是您想要的。您只需使用下面的代码就可以得到您想要的: $column_names = DB::getSchemaBuilde
$column_names = DB::getSchemaBuilder()->getColumnListing('tablename');
但是有没有一种方法可以返回每个特定列上的可接受值?例如,我有许多列是
enum
s,我想返回这些列(可能在多维数组中),这样我就可以在单元测试中使用它。getDoctrineColumn
就是您想要的。您只需使用下面的代码就可以得到您想要的:
$column_names = DB::getSchemaBuilder()->getColumnListing('tablename');
foreach($column_names as $c){
$type = DB::connection()->getDoctrineColumn('tablename', $c)->getType()->getName();
// do anything you want with your desired type
}
这将只返回其类型,如“字符串”、“整数”等,而不是“约束”,如“每周一次”、“每天一次”etc@mike3875您在问题中询问了可接受的值。约束不是可接受的值。你说的一周一次是什么意思?它是如何设置的?这是我的迁移中的一行
$table->enum('gender',['m','f','o'])->nullable()代码>。所谓可接受值,我指的是‘m’、‘f’或‘o’。像这样。