Answers for "laravel eloquent get column names"

SQL
1

get table column names sql laravel

use IlluminateSupportFacadesSchema;

use IlluminateSupportFacadesDB;

public function getTableColumns($table)
{
    return DB::getSchemaBuilder()->getColumnListing($table);

    // OR

    return Schema::getColumnListing($table);

}
Posted by: Guest on December-05-2020
1

laravel eloquent get column

//return array of json
Model::where('id', 1)->get(['column1','column2']);
or
Model::all(['column1']);
//return array
Model::whereNull('deleted_at')->pluck('column1');
Posted by: Guest on March-23-2021
0

laravel get column field name

// You may need to run
composer require doctrine/dbal
// Retrieve laravel column type
$columnType = DB::getSchemaBuilder()->getColumnType($tableName, $colName)
// for example
$columnType = DB::getSchemaBuilder()->getColumnType('user', 'age')
Posted by: Guest on November-02-2020

Code answers related to "laravel eloquent get column names"

Code answers related to "SQL"

Browse Popular Code Answers by Language