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

String Morpher Laravel Package

ssolweb/string-morpher

ssolweb/string-morpher offers a fluent PHP/Laravel API for morphing strings into common formats like camelCase, snake_case, slug, and studly case, plus custom rules for reusable, consistent string transformations.

View on GitHub
Deep Wiki
Context7

Getting Started

The v1.1.5 release is additive: three new transformers (slugify, wrap, unwrap) join the existing transformation pipeline. There are no breaking changes, so this is a safe upgrade.

Start by locating the transformer registry/service provider that the package publishes. In a typical setup you'll find:

  • A config file (config/transformers.php or similar) listing available transformers.
  • A base Transformer contract with a transform() method.
  • A pipeline/chainable entry point used in models, requests, or resources.

Minimal first use case — normalising a title-style attribute before persisting it:

$value = transform('Hello World')
    ->slugify()      // "hello-world"
    ->wrap('"');     // "\"hello-world\""

Then walk it back with unwrap when reading:

transform('"hello-world"')->unwrap('"'); // "hello-world"

Look first at the changelog-linked PRs (#58, #56, #55) for exact method signatures and argument defaults (e.g. whether wrap defaults to a single character, whether slugify accepts a separator). Confirm behaviour against the published docs rather than assuming parity with Str::slug().

Implementation Patterns

Model accessors / casts. Chain transformers in an accessor or custom cast so slug generation and display formatting stay declarative:

protected function slug(): Attribute
{
    return Attribute::make(
        set: fn ($value) => transform($value)->slugify(),
    );
}

Form request sanitisation. Slugify user-supplied identifiers (category names, tags, permalinks) in prepareForValidation() so downstream validation and uniqueness checks see the canonical form:

protected function prepareForValidation(): void
{
    $this->merge([
        'slug' => transform($this->input('slug') ?? $this->input('name'))->slugify(),
    ]);
}

Import/seed normalisation. When ingesting CSVs or legacy data, pipe each row's string fields through slugify then wrap/unwrap to strip inconsistent quoting or bracket decoration before insert. This is the cleanest fit for the new unwrap transformer — legacy exports frequently pad values with prefixes/suffixes.

API resources. Apply unwrap when returning values that were stored with presentation wrappers, and wrap when an external consumer expects a formatted string. Keep wrapping at the resource layer rather than in the database, so storage stays canonical.

Composing chains. Prefer a single fluent chain over repeated local variables. Because transformers are additive and stateless-looking, order matters: normalise first (slugify), then decorate (wrap), and reserve unwrap for input cleanup. Build small named helper methods (e.g. normaliseSlug()) rather than duplicating chains across models.

Testing. Add a data-provider test around each chain you rely on, especially edge cases: empty strings, strings already containing the wrapper, unicode input, and multiple consecutive separators. This guards against future transformer changes altering chain output.

Gotchas and Tips

  • Idempotency of wrap. Calling wrap on an already-wrapped value will double-wrap. Guard with an unwrap first, or check Str::startsWith/Str::endsWith before applying.
  • unwrap is prefix/suffix-only. Per the release notes it removes a prefix and/or suffix — it is not a general-purpose trim replacement for arbitrary characters. Use PHP's trim() when you need character-class trimming.
  • slugify is not necessarily Str::slug. Verify separator handling, transliteration, and whether it lowercases. Don't assume identical output to Laravel's helper when your slugs back route model binding or unique indexes.
  • Unique constraint ordering. If you slugify in a mutator, run your uniqueness check after transformation, otherwise two distinct inputs can collide on write.
  • Dependency bump is docs-only. The json bump under /docs (dependabot #57) doesn't affect runtime; no action needed in application composer constraints.
  • Debugging chains. When a chain produces unexpected output, isolate each transformer in a tinker session step by step. Transformer chains are hard to inspect mid-pipeline; splitting the chain is faster than reasoning about the whole.
  • Configuration quirks. If transformers are registered via config, run php artisan config:clear after upgrades — cached config can hide newly registered transformers added in a minor release.
  • Extension point. Implement the package's transformer contract for domain-specific normalisation (e.g. stripping internal SKU prefixes) and register it alongside the built-ins, rather than scattering str_replace calls through your codebase.
  • Upgrade safety. v1.1.5 is purely additive; pin with ^1.1 and review the changelog for further transformer additions, which are the most likely source of behaviour drift in chains you already rely on.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource