我正在尝试从sql视图获取列名,我的视图如下所示:
name type building_id
test type_test 5
test2 type2_test 6
我想获取名称(名称和类型以及building_id) 我尝试了Laravel函数getColumnListing()但我得到了空数组
答案 0 :(得分:0)
尝试
\Illuminate\Support\Facades\DB::select('show columns from table_name');
// table_name must be db table name
结果
array:5 [▼
0 => {#309 ▼
+"Field": "id"
+"Type": "int(10) unsigned"
+"Null": "NO"
+"Key": "PRI"
+"Default": null
+"Extra": "auto_increment"
}
1 => {#311 ▼
+"Field": "name"
+"Type": "varchar(100)"
+"Null": "NO"
+"Key": ""
+"Default": null
+"Extra": ""
}
2 => {#312 ▶}
3 => {#313 ▶}
4 => {#314 ▶}
]