4

I'm new to laravel

I have post table, this table has 10 columns.

So i want to get all column names in model Laravel Does this feature already work??

Or do I have to make it myself ??

Any suggestion or advice would be appreciated.

Thank you in advance

Hax0r
  • 1,722
  • 4
  • 25
  • 43
  • 1
    Possible duplicate of [Trying to get all column names in a table](https://stackoverflow.com/questions/31069859/trying-to-get-all-column-names-in-a-table) – Maraboc Jan 08 '18 at 08:53

2 Answers2

6

You can use the getColumnListing() method:

use Schema;
Schema::getColumnListing($this->getTable())
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
2
$columns = Schema::getColumnListing('posts');
dd($columns);
Imran
  • 3,031
  • 4
  • 25
  • 41