[英]Get table schema using eloquent, get Array to string conversion error
i'm trying to get a list of the column data types for a certain table. 我正在尝试获取特定表的列数据类型的列表。 I have noticed eloquent has some methods that do this so i'm trying to use these.
我已经注意到雄辩有一些方法可以做到这一点,所以我试图使用这些方法。
$grammar = DB::connection()->getSchemaBuilder();
$schema = DB::select($grammar->getColumnListing('vehicles'));
However i'm getting the following error when calling getColumnListing
: 但是,调用
getColumnListing
时出现以下错误:
Array to string conversion
数组到字符串的转换
Not too sure where this so called Array
is... the method expects a String
: 不太确定这个所谓的
Array
在哪里...该方法需要一个String
:
vendor\\laravel\\framework\\src\\Illuminate\\Database\\Schema\\Builder.php 供应商\\ laravel \\框架的\\ src \\照亮\\数据库\\架构\\ Builder.php
/**
* Get the column listing for a given table.
*
* @param string $table
* @return array
*/
public function getColumnListing($table)
{
$table = $this->connection->getTablePrefix().$table;
$results = $this->connection->select($this->grammar->compileColumnListing($table));
return $this->connection->getPostProcessor()->processColumnListing($results);
}
Laravel only provides a list of column names: Laravel仅提供列名称列表:
Schema::getColumnListing('vehicles');
You can get more details by installing the doctrine/dbal
package: 您可以通过安装
doctrine/dbal
软件包来获取更多详细信息:
Schema::getConnection()->getDoctrineSchemaManager()->listTableColumns('vehicles');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.