Created
November 7, 2014 09:48
-
-
Save prodeveloper/027f51f905d3916ab5b9 to your computer and use it in GitHub Desktop.
Get All Columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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