Skip to content

Instantly share code, notes, and snippets.

@alejandrogih
Created January 13, 2017 19:03
Show Gist options
  • Save alejandrogih/955d78358c0b4a9e8a53f8751e284898 to your computer and use it in GitHub Desktop.
Save alejandrogih/955d78358c0b4a9e8a53f8751e284898 to your computer and use it in GitHub Desktop.
Laravel get column names and types
$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;
@alejandrogih
Copy link
Author

This was very useful to create the validation array on my CRUDs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment