Created
January 13, 2017 19:03
-
-
Save alejandrogih/955d78358c0b4a9e8a53f8751e284898 to your computer and use it in GitHub Desktop.
Laravel get column names and types
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
$column_name = "table_name"; | |
$columns = DB::select('show columns from ' . $column_name); | |
foreach ($columns as $value) { | |
echo "'" . $value->Field . "' => '" . $value->Type . "|" . ( $value->Null == "NO" ? 'required' : '' ) ."', <br/>" ; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very useful to create the validation array on my CRUDs