laravel eloquent get column names code example
Example 1: laravel eloquent get column
Model::where('id', 1)->get(['column1','column2']);
or
Model::all(['column1']);
Model::whereNull('deleted_at')->pluck('column1');
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 get column field name
composer require doctrine/dbal
$columnType = DB::getSchemaBuilder()->getColumnType($tableName, $colName)
$columnType = DB::getSchemaBuilder()->getColumnType('user', 'age')