Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get table column names as array from model

Tags:

laravel

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

like image 791
Hax0r Avatar asked Jan 29 '23 21:01

Hax0r


2 Answers

You can use the getColumnListing() method:

use Schema;
Schema::getColumnListing($this->getTable())
like image 155
Alexey Mezenin Avatar answered Feb 05 '23 14:02

Alexey Mezenin


$columns = Schema::getColumnListing('posts');
dd($columns);
like image 42
Imran Avatar answered Feb 05 '23 14:02

Imran