Last active
December 18, 2024 17:01
-
-
Save code-poel/f9f627b57476c4a3beca to your computer and use it in GitHub Desktop.
Get schema metadata on Laravel tables or columns...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://stackoverflow.com/questions/18562684/how-to-get-database-field-type-in-laravel/18563159#18563159 | |
/* @var $schema \Doctrine\DBAL\Schema\AbstractSchemaManager */ | |
$schema = DB::getDoctrineSchemaManager(); | |
$columns = $schema->listTableColumns('cities'); | |
dd($columns); | |
/* | |
array:6 [▼ | |
"id" => Column {#324 ▼ | |
#_type: IntegerType {#310} | |
#_length: null | |
#_precision: 10 | |
#_scale: 0 | |
#_unsigned: true | |
#_fixed: false | |
#_notnull: true | |
#_default: null | |
#_autoincrement: true | |
#_platformOptions: [] | |
#_columnDefinition: null | |
#_comment: null | |
#_customSchemaOptions: [] | |
#_name: "id" | |
#_namespace: null | |
#_quoted: false | |
} | |
"country_id" => Column {#326 ▶} | |
"name" => Column {#327 ▼ | |
#_type: StringType {#313} | |
#_length: 255 | |
#_precision: 10 | |
#_scale: 0 | |
#_unsigned: false | |
#_fixed: false | |
#_notnull: true | |
#_default: null | |
#_autoincrement: false | |
#_platformOptions: array:1 [▶] | |
#_columnDefinition: null | |
#_comment: null | |
#_customSchemaOptions: [] | |
#_name: "name" | |
#_namespace: null | |
#_quoted: false | |
} | |
"slug" => Column {#328 ▶} | |
"created_at" => Column {#329 ▶} | |
"updated_at" => Column {#330 ▶} | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment