[Feature Request]: Additional Variables
Feature Description
| variable | output | plural | output |
|---|---|---|---|
| {{ model.lower }} | user account | {{ model.lowerPlural }} | user accounts |
| {{ model.title }} | User Account | {{ model.titlePlural }} | User Accounts |
| {{ model.upper }} | User account | {{ model.upperPlural }} | User accounts |
| {{ model.studly }} | UserAccount | {{ model.studlyPlural }} | UserAccounts |
| {{ model.camel }} | userAccount | {{ model.camelPlural }} | userAccounts |
| {{ model.slug }} | user-account | {{ model.slugPlural }} | user-accounts |
| {{ model.snake }} | user_account | {{ model.snakePlural }} | user_accounts |
The slug is good for file paths like views or route names like product-categories.index Inertia uses OrderItems/Index view format and MODEL_CLASS_VARIABLE_PLURAL is neeeded
Str::macro('reset', function ($value) {
return Str::of($value)->snake()->replace('_', ' ')->singular();
});
This reset was needed because multiple word models
Str::slug('AccountUser') == accountuser
Above didn't work, but this does:
Str::reset('AccountUser')->slug() == account-user
'title' => function ($value) {
return Str::reset($value)->title();
},
'studly' => function ($value) {
return Str::reset($value)->studly();
},
'camel' => function ($value) {
return Str::reset($value)->camel();
},
'slug' => function ($value) {
return Str::reset($value)->slug();
},
'snake' => function ($value) {
return Str::reset($value)->snake();
},
'lowerPlural' => function ($value) {
return Str::reset($value)->plural();
},
'titlePlural' => function ($value) {
return Str::reset($value)->plural()->title();
},
'studlyPlural' => function ($value) {
return Str::reset($value)->plural()->studly();
},
'camelPlural' => function ($value) {
return Str::reset($value)->plural()->camel();
},
'slugPlural' => function ($value) {
return Str::reset($value)->plural()->slug();
},
'snakePlural' => function ($value) {
return Str::reset($value)->plural()->snake();
},
Hi, Brian.
I already have something very similar for all variables with the "_CLASS" prefix - https://laravel-idea.com/docs/custom_generations#code_templates I'll try to add the same for the main class name. Thank you.
@adelf yes Im using them.. and was suggesting adding more variations. Having slug, title, lower, studly, snake, uppercase, and camel. And then appending PLURAL for all like my table shows would be amazing. Would be great if any variable automatically had all variations
@adelf are variables available in directory / parameter paths?
directory: views/${MODEL_SLUG_PLURAL}/index.vue
directory: views/products/index.vue
directory: views/product-categories/index.vue
For custom generations?
@adelf yes, for custom generations. Great feature btw.
I'll try to add. Thanks for the great suggestions!
@adelf thank you!
I've added some template variables in the last update. https://laravel-idea.com/docs/custom_generations#code_templates But using them in the paths is still not supported.
@adelf thank you! Looks great.. only one I can think of is title case UserAccount User Account. I appreciate you adding these variables though.