laravel db get table fields code example
Example 1: laravel get list of columns in a table
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
public function getTableColumns($table)
{
return DB::getSchemaBuilder()->getColumnListing($table);
return Schema::getColumnListing($table);
}
Example 2: get table column names sql laravel
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
public function getTableColumns($table)
{
return DB::getSchemaBuilder()->getColumnListing($table);
return Schema::getColumnListing($table);
}
Example 3: laravel show table columns
Schema::getColumnListing($table);
Example 4: laravel get column field name
composer require doctrine/dbal
$columnType = DB::getSchemaBuilder()->getColumnType($tableName, $colName)
$columnType = DB::getSchemaBuilder()->getColumnType('user', 'age')