du9826 2019-02-11 15:03
浏览 84

如何从Laravel的sql server视图中获取列名

I am trying to get columns name from sql view, my view appear like this:

name       type         building_id
test       type_test    5
test2      type2_test   6

I want to get names(name & type & building_id) I tried Laravel function getColumnListing() but i get null array

  • 写回答

1条回答 默认 最新

  • dongmou3615 2019-02-11 15:32
    关注

    Try this

    \Illuminate\Support\Facades\DB::select('show columns from table_name'); 
    // table_name must be db table name 
    

    Result

    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 ▶}
    ]
    
    评论

报告相同问题?