2

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

Community
  • 1
  • 1
Arbitur
  • 38,684
  • 22
  • 91
  • 128

2 Answers2

4

You can do:

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

And use DB; to import the needed dependencies.

Björn
  • 5,696
  • 1
  • 24
  • 34
2

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;
lesssugar
  • 15,486
  • 18
  • 65
  • 115
  • I had no ide I could just do use Schema. Dont I have to add a path to the classes? Where is shema? – Arbitur Jun 26 '15 at 11:45
  • 1
    By using `use Schema;` you are calling a Facade. Laravel provides plenty of those. Just take a look here: http://laravel.com/docs/5.1/facades – lesssugar Jun 26 '15 at 12:15