Skip to content

format ​

File: src/Helpers/format.php

The largest helper file — 45+ functions covering string casing, class reflection, code generation, data access, and closure transformation utilities.

String Casing ​

FunctionSignatureDescription
lowerName(string $name): stringLowercases the name
studlyName(string $name): stringConverts to StudlyCase via Str::studly()
camelCase(string $name): stringConverts to camelCase via Str::camel()
kebabCase(string $name): stringConverts to kebab-case via Str::kebab()
snakeCase(string $name): stringConverts to snake_case via Str::snake()
pluralize(string $name): stringReturns plural form via Str::plural()
singularize(string $name): stringReturns singular form via Str::singular()
headline(string $name): stringConverts to Headline Case via Str::headline()
tableName(string $name): stringConverts to plural snake_case table name
camelCaseToWords(string $name): stringSplits camelCase into space-separated words
is_plural(string $name): boolReturns whether the string is already plural

Foreign Key / Morph Naming ​

FunctionSignatureDescription
makeForeignKey(string $model): stringuser → user_id
makeMorphToName(string $model): stringReturns morph-to relation name
makeMorphName(string $model): stringReturns morph type name (without _type)
makeMorphForeignKey(string $model): stringReturns {model}_id for polymorphic pivot
makeMorphForeignType(string $model): stringReturns {model}_type for polymorphic pivot
makeMorphToMethodName(string $model): stringReturns morphTo method name
makeMorphPivotTableName(string $model): stringReturns pivot table name for a morph pivot
getMorphModelName(string $tableName): stringStrips able/ables suffix to get model name

Class / Namespace Reflection ​

FunctionSignatureDescription
abbreviation(string $name): stringBuilds an abbreviation from underscored words (e.g. user_profile → up)
get_class_short_name(string $class): stringReturns the unqualified class name from a FQCN
class_resolution(string $class): stringResolves a class alias or short name to its FQCN
class_namespace(string $class): stringExtracts the namespace from a FQCN
fileTrace(string $pattern): stringSearches debug_backtrace() for a file path matching the regex $pattern

Code Generation ​

These helpers write PHP source fragments used by make:* console commands.

FunctionSignatureDescription
get_file_string(string $path): stringReads a stub file
replace_curly_braces(string $stub, array $replacements): stringReplaces tokens in a stub string
indent(string $content, int $level = 1): stringIndents content by $level × 4 spaces
comment_string(string $text): stringWraps text in a /* ... */ comment block
method_string(string $name, string $body, ...): stringGenerates a PHP method declaration
attribute_string(string $name, mixed $value): stringGenerates a PHP class attribute line
concatenate_path(string ...$parts): stringJoins path segments with /, deduplicating slashes
concatenate_namespace(string ...$parts): stringJoins namespace segments with \\
get_file_class(string $path): stringExtracts the class name from a PHP file

Validation / Rules ​

FunctionSignatureDescription
parseRulesSchema`(stringarray $rules): array`
formatRulesSchema(array $rules): stringConverts rules array back to pipe-delimited string

Data Access ​

FunctionSignatureDescription
getValueOrNull(array $data, string $key): mixedReturns $data[$key] or null if missing
tryOperation(callable $fn, mixed $default = null): mixedExecutes $fn, returns $default on any Throwable
data_get_with_dot_keys(array $data, string $key): mixedLike data_get() but treats literal dot-keys as single keys first
data_set_with_dot_keys(array &$data, string $key, mixed $value): voidLike data_set() but handles literal dot-keys
wrapImplode(string $separator, array $array, string $prepend, string $append): stringImplodes array with optional prefix/suffix

Relationship Map ​

FunctionSignatureDescription
laravelRelationshipMap(): arrayReturns the cached Eloquent relationship type map
saveLaravelRelationshipMap(array $map): voidPersists the relationship map to the modularous cache

Routing / Display ​

FunctionSignatureDescription
modelShowFormat(mixed $model): stringReturns the display string for a model instance
nestedRouteNameFormat(string $routeName): stringFormats a nested route name for display

User ​

FunctionSignatureDescription
get_user_profile(): arrayReturns the authenticated user's profile data array
name_surname_resolver(string $fullName): arraySplits a full name string into ['name' => ..., 'surname' => ...]

Variable Replacement ​

FunctionSignatureDescription
replace_variables_from_haystack(string $haystack, array $vars): stringReplaces {KEY} tokens using $vars
extract_schema_extensions(array $schema): arrayExtracts ext values from a form schema
transform_closure_value(mixed $value, bool $forceArray = false): mixedIf $value is a Closure, calls it and returns the result
transform_closure_values(array $data, bool $forceArray = false): arrayMaps transform_closure_value over an array