
Table::getSchema() 메소드는 테이블의 모든 컬럼을 반환합니다. 컬럼 이름과 데이터 타입을 같이 반환하려면, 다음과 같이 컬럼 이름과 데이터 타입을 함께 반환하는 메소드를 사용할 수 있습니다.
#hostingforum.kr
php
$table = DB::table('테이블명');
$schema = $table->getSchema();
foreach ($schema->getColumns() as $column) {
echo $column->getName() . ' - ' . $column->getType() . PHP_EOL;
}
컬럼 이름을 지정하여 특정 컬럼만 반환하려면, 다음과 같이 컬럼 이름을 지정하여 반환하는 메소드를 사용할 수 있습니다.
#hostingforum.kr
php
$table = DB::table('테이블명');
$schema = $table->getSchema();
foreach ($schema->getColumns() as $column) {
if ($column->getName() == '컬럼이름') {
echo $column->getName() . ' - ' . $column->getType() . PHP_EOL;
}
}
또는, 컬럼 이름을 배열로 지정하여 반환할 수 있습니다.
#hostingforum.kr
php
$table = DB::table('테이블명');
$schema = $table->getSchema();
$컬럼이름 = ['컬럼이름1', '컬럼이름2'];
foreach ($schema->getColumns() as $column) {
if (in_array($column->getName(), $컬럼이름)) {
echo $column->getName() . ' - ' . $column->getType() . PHP_EOL;
}
}
2025-05-26 23:42