Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Case Converter Laravel Package

jawira/case-converter

Convert strings between 13 naming conventions with jawira/case-converter: camel, Pascal, snake, Ada, macro, kebab, train, Cobol, title, sentence, dot and more. It auto-detects the input format, offers a factory, and supports i18n.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require jawira/case-converter

v3.7.0 requires PHP 8.2+ (see Gotchas). Start by converting simple strings using the CaseConverter class. The most common first use case is normalizing user input or API payloads into snake_case or camelCase for consistent internal handling:

use Jawira\CaseConverter\CaseConverter;

$converter = new CaseConverter();
$camel = $converter->toCamelCase('user_first_name');     // 'userFirstName'
$snake = $converter->toSnakeCase('UserName');            // 'user_name'
$kebab = $converter->toKebabCase('fileNameWithNumbers'); // 'file-name-with-numbers'

Check the README on GitHub or the Packagist page for the full list of supported cases (toAdaCase(), toCobolCase(), toTrainCase(), etc.).

Implementation Patterns

  • Input Sanitization: Wrap form or API input with conversion to a canonical format (e.g. toSnakeCase()) before processing to unify data structures across services.
  • Dynamic Property Mapping: When hydrating objects from external data (e.g. JSON responses with inconsistent casing), use toCamelCase() or toPascalCase() to match PHP property naming standards.
  • Language/Adapter Interoperability: Normalize strings when interfacing with systems expecting specific conventions (e.g. toSnakeCase() for database columns, toKebabCase() for URL slugs).
  • Middleware for Header Keys: In HTTP middleware, convert header keys to a consistent convention like toKebabCase() if downstream services require it.
  • Testing Helpers: Use CaseConverter in test fixtures to generate predictable variable names or identifiers across multiple conventions.
  • Service Wrapper: Encapsulate conversion behind a small project service to enforce domain-specific rules (e.g. always uppercase known acronyms after conversion).

Gotchas and Tips

  • PHP 8.2 minimum (v3.7.0): Release v3.7.0 updates the codebase to PHP 8.2. If your application runs PHP 8.1 or lower, pin to ^3.6 instead of upgrading. Check composer.json in the package for the exact constraint.
  • No API changes in v3.7.0: The release notes only mention tooling updates (PHPUnit, Behat, CodeClimate removal) and documentation wording. Existing conversion methods and behaviour are unchanged, so this is a safe upgrade for PHP 8.2+ users.
  • Version pinning: Use ^3.7 or ~3.7 to stay on the current major line. Avoid floating dev-main in production.
  • Acronym Handling: The package handles acronyms intelligently in most cases (e.g. toSnakeCase('HTTPRequest') → 'http_request'), but irregular inputs like 'APIV2' may produce unexpected splits. Validate edge cases with a quick unit test.
  • Performance: Avoid excessive conversions in tight loops; cache intermediate results when repeatedly processing the same strings.
  • Case Insensitivity: Conversion methods treat input case-insensitively but output strictly follows the target convention. Use toLower() or toUpper() beforehand if you need to pre-normalize.
  • Extension Points: The package does not support custom converters directly, but you can wrap it in a service class to enforce project-specific rules (e.g. force 'uuid' → 'UUID' after conversion).
  • Debugging Tips: If conversion fails or returns empty strings, verify input is non-empty and UTF-8 compliant. Invalid multibyte sequences can cause silent failures.
  • Release Stability: v3.7.0 is a minor release with a PHP version bump. Monitor the changelog and pin minor versions (~3.7) to avoid surprise requirement changes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
adachsoft/changelog-linter