Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all column name from a table in laravel?

I have tried to get all column names from a table Teller

Function:

public function getTableColumns($tables) {     return DB::select(DB::raw('SELECT                                      COLUMN_NAME,                                      DATA_TYPE,                                      COLUMN_DEFAULT                                 FROM                                      INFORMATION_SCHEMA.COLUMNS                                 WHERE                                      table_name = `Teller`')); } 
like image 213
DMS-KH Avatar asked May 11 '16 08:05

DMS-KH


1 Answers

You can get all columns name by simply doing that...

use Illuminate\Support\Facades\Schema;  use Illuminate\Support\Facades\DB;  public function getTableColumns($table) {     return DB::getSchemaBuilder()->getColumnListing($table);      // OR      return Schema::getColumnListing($table);  } 
like image 53
Parvez Rahaman Avatar answered Sep 30 '22 19:09

Parvez Rahaman