How to get database field type in Laravel?

后端 未结 9 2093
离开以前
离开以前 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:14

    GET All Details of fields of table

    DB::select('describe table_name');
    

    Example:-

    DB::select('describe users');
    

    Response will be like this

     Array
    (
        [0] => stdClass Object
            (
                [Field] => id
                [Type] => int(11)
                [Null] => NO
                [Key] => PRI
                [Default] => 
                [Extra] => auto_increment
            )
    
        [1] => stdClass Object
            (
                [Field] => user_group_id
                [Type] => int(11) unsigned
                [Null] => YES
                [Key] => MUL
                [Default] => 
                [Extra] => 
            )
    
        [2] => stdClass Object
            (
                [Field] => username
                [Type] => varchar(100)
                [Null] => YES
                [Key] => MUL
                [Default] => 
                [Extra] => 
            )
     )
    

提交回复
热议问题