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

Inflect Laravel Package

mmucklo/inflect

A lightweight PHP inflector for converting English words between singular and plural forms and transforming strings into camelCase, snake_case, humanized, and class-name formats. Useful for ORM table naming, scaffolding, and any app that needs reliable word inflection without heavy dependencies.

View on GitHub
Deep Wiki
Context7

Getting Started

composer require mmucklo/inflect

The package is framework-agnostic and requires no service provider, facade, or config file in a Laravel app. It exposes a static-style API (typically Mmucklo\Inflect\Inflect::pluralize() / singularize() / camelize() / tableize() / classify()) that mirrors the Doctrine Inflector contract but memoizes results in a process-local cache. Look at the source src/ first — it is small, and the memoization layer is the only thing that differs from a plain Doctrine Inflector.

The first use case to validate is batching: anywhere you call Str::plural() or an inflector in a loop over the same handful of words (route-name generation, dynamic table/column naming, seeder factories that map many model names). Drop-in the call and confirm identical output to Laravel’s own helpers:

use Mmucklo\Inflect\Inflect;

Inflect::pluralize('category');   // categories
Inflect::tableize('UserProfile'); // user_profiles

If the output matches Str::plural()/Str::snake() for your domain vocabulary, you have a safe starting point; if it diverges, treat the package as an addition, not a replacement.

Implementation Patterns

Memoized batch mapping. Use Inflect when you are classifying or tableizing a fixed set of names repeatedly (e.g. building a lookup of Model => table for a generic repository, or generating route names for all resources in a module registry). The cache pays off on the second and subsequent calls; for a single call per word, Str is equally fast and already loaded.

Wrap it behind your own helper. Because the package is small and low-activity, put it behind a thin class (App\Support\Naming) or an interface so you can swap to Doctrine or Laravel’s Str without touching call sites:

final class Naming
{
    public static function table(string $model): string
    {
        return Inflect::tableize($model);
    }
}

Use it in generators and Artisan commands. Custom make:* commands that pluralize/singularize class names, relationship method names, or migration table names benefit most from memoization when they process many entities in one process.

Keep pluralization decisions in one place. Laravel migrations and models should agree on table names. Centralizing through a wrapper means you flip implementations once if you later drop the dependency.

Mix with Str deliberately. It is fine to use Str::plural() for ad-hoc calls and Inflect inside hot loops. Do not scatter both styles across the same domain area; that is where divergent pluralization bites you.

Gotchas and Tips

  • Unbounded input = unbounded cache. Memoization is process-static. If you feed user-supplied words (e.g. tag slugs, tenant-generated names) into the inflector, the cache grows for the life of the worker. In queue workers or Octane this can leak. Restrict it to bounded, code-derived vocabularies.
  • It is not a Str replacement. Rule sets differ from Laravel’s. Irregular and compound words (person/people, analysis/analyses, data) can produce different results between Inflect and Str. Test your actual domain vocabulary before swapping.
  • No Laravel integration surface. No config, no container binding, no publishable assets. Do not expect to tune rules via config; if you need custom rules you are back to Doctrine or Str::plural’s $count/custom logic.
  • Debugging cache behavior. To confirm hits vs misses, add temporary logging around a wrapper method or use reflection on the static cache array — there is no built-in stats API.
  • PHP-FPM resets, Octane/queue workers do not. In classic FPM, the cache naturally resets each request; in long-lived processes it persists, so validate memory under the workloads you actually run.
  • Low activity / low adoption. 40 stars and zero dependents means limited community support and a maintenance risk. Pin the version in composer.json and keep the wrapper thin so removal is trivial.
  • License is NOASSERTION. Verify the license text in the repo before using it in a commercial codebase; don’t assume MIT.
  • Extension points are minimal. If you need to add irregular rules, prefer Doctrine’s Inflector with your own caching decorator — that gives you the same memoization benefit with a larger rule set and a maintained upstream.
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