How to get database field type in Laravel?

后端 未结 9 2120
离开以前
离开以前 2020-12-14 01:38

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

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 02:28

    Within the model: laravel5.x

        $temp = $this->newQuery()->fromQuery("SHOW FIELDS FROM ".$this->getTable());
    
        foreach($temp as $val){
           echo 'Field: '.$val->Field;
           echo 'Type: '.$val->Type;
       }
    

提交回复
热议问题