Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Created November 7, 2014 09:48
Show Gist options
  • Save prodeveloper/027f51f905d3916ab5b9 to your computer and use it in GitHub Desktop.
Save prodeveloper/027f51f905d3916ab5b9 to your computer and use it in GitHub Desktop.
Get All Columns
<?php
namespace Model\Processors;
use DB;
/**
* Class GetAllColumns
* @package Model\Processors
* - See more at: http://laravelsnippets.com/snippets/get-all-columns-names-from-a-eloquent-model#sthash.wgqPKvG9.dpuf
*/
trait GetAllColumns
{
function getAllColumns()
{
$query = 'SHOW COLUMNS FROM ' . $this->getTable();
foreach (DB::select($query) as $column) {
$columns[] = $column->Field;
}
return $columns;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment