Arbitur
Arbitur

Reputation: 39081

Trying to get all column names in a table

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");

I get error:

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

Upvotes: 2

Views: 1396

Answers (2)

lesssugar
lesssugar

Reputation: 16181

To address the initial problem, the reason why it did not work for you is because you should have simply used this:

use Schema;

instead of this:

use Illuminate\Database\Schema\Builder as Schema;

Upvotes: 2

Björn
Björn

Reputation: 5876

You can do:

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

And use DB; to import the needed dependencies.

Upvotes: 4

Related Questions