get column names from table laravel code example
Example 1: 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 2: laravel get column field name
composer require doctrine/dbal
$columnType = DB::getSchemaBuilder()->getColumnType($tableName, $colName)
$columnType = DB::getSchemaBuilder()->getColumnType('user', 'age')