尝试获取表中的所有列名 [英] Trying to get all column names in a table

查看:53
本文介绍了尝试获取表中的所有列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了答案,据说这样做是这样的:

I found this answer which says to do like this:

$columns = Schema::getColumnListing('users');

但是它没有说要使用什么,但是我想应该是:

But it doesnt say what to use, but I suppose it should be:

use Illuminate\Database\Schema\Builder as Schema;

但是当我尝试它不起作用时:

But when I try it it doesnt work:

$columns = Schema::getColumnListing("users");

我收到错误消息:

假设$ this来自不兼容的上下文,则不应静态调用非静态方法Illuminate \ Database \ Schema \ Builder :: getColumnListing()

Non-static method Illuminate\Database\Schema\Builder::getColumnListing() should not be called statically, assuming $this from incompatible context

推荐答案

您可以这样做:

$columns = DB::getSchemaBuilder()->getColumnListing('users');

然后使用DB; 导入所需的依赖项.

And use DB; to import the needed dependencies.

这篇关于尝试获取表中的所有列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆