Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Laravel模式生成器返回列约束_Php_Laravel_Laravel 5.1 - Fatal编程技术网

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’。像这样。