Reputation: 293
I'm using Laravel 5.4 and a MySQL database. In a view I want to display dynamically all my models attributes. ( Key : Value. , for example Name : John )
But these models attributes are the table colums names, so they are not in a nice formatting ( lower case, with some underscore )
What is the best way in Laravel to display nice name instead of database table columns names ?
Upvotes: 0
Views: 657
Reputation: 11906
Here's a simple function to prettify your field names.
function prettify_field($field)
{
return title_case(snake_case(camel_case($field), ' '));
}
Sample output
name Name
age Age
created_at Created At
totalAmount Total Amount
birth_date Birth Date
theirPetName Their Pet Name
Upvotes: 5