How to get table column names from a database table in Eloquent?

Laravel: How to get table column names from a database table in Eloquent?

There are a few methods to get the table column info in Eloquent

  1. \Schema::getColumnListing($this->table)

  1. class User extends Model {
  2.     public function getTableColumns() {
  3.         return $this
  4.             ->getConnection()
  5.             ->getSchemaBuilder()
  6.             ->getColumnListing($this->getTable());
  7.     }
  8. }

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to get table column names from a database table in Eloquent?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find out what version of Laravel you are using?

How to redirect your website to a new domain/location in .htaccess

How to see all of the options for an artisan command?

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to add the CSRF (Cross-site request forgery) token in Laravel?

How to make multiple routes share the same URL structure or URL parameters

How to find out which php.ini file PHP is using?

How to review blog posts (written by other users) before they get published on your WordPress blog?

How to force non www in htaccess

How to split a string into an array, in JS