Adsense
Popular Posts
- Install APXS in Redhat Linux
- MySQL workbench -"Could not decrypt password cache"
- Transfer modules between sites
- JavaScript, remove trailing insignificant zeros after toFixed function
- Set Windows path command line
- datatable order by nunmeric
- MySQL date created and date modified
- super(props) in React
- PHP, dump varailbes in a format way
- React: connect(mapStateToProps, mapDispatchToProps)
Tuesday, February 8, 2022
Laravel: get enum values of a column in MySQL table
public function get_enum_values($table, $field){
$enum = [];
$test=DB::select(DB::raw("show columns from {$table} where field = '{$field}'"));
if(!empty($test)){
preg_match('/^enum\((.*)\)$/', $test[0]->Type, $matches);
foreach( explode(',', $matches[1]) as $value )
{
$enum[] = trim( $value, "'" );
}
}
return $enum;
}
Labels:
Laravel
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment