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 Laravel Package

spatie/string

spatie/string is a PHP package for fluent, chainable string handling. Wrap any native string with the string() helper, then chain methods like between, toUpper, and toLower, or use array-style offsets to read and modify individual characters easily.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Display-layer polish, not core capability. The methods that show up in product work are tease() (word-safe truncation for cards, meta descriptions, previews), possessive() ("Bob's" / "Charles'"), and between() for extracting a phrase out of templated content. These are the "make the UI read like a human wrote it" details — the kind of thing that gets deferred forever unless it's a one-liner.
  • Content-derived navigation and URL logic. segment(), firstSegment(), lastSegment(), and pop() are directly useful for breadcrumbs, taxonomy paths, and stripping a trailing slug off a deep link. Chained pop()->pop() is a cheap way to compute a parent path without a router-adjacent helper.
  • Copy and placeholder generation. replaceFirst() / replaceLast() (replace only the first "Hi {{name}}" without touching later occurrences), prefix() / suffix(), and toUpper() / toLower() are the small, high-frequency transformations that appear in templating, admin tooling, and generated notifications.
  • A build-vs-buy line that resolves to "buy, but check the shelf first." The realistic PM decision is not "should we adopt this" but "should we keep hand-rolling string helpers in our own Support\Str class or helpers.php." Adopting gives a documented, MIT-licensed, test-covered equivalent for near-zero effort; the counterweight is that Laravel's own Str / Stringable already covers between, limit (≈ tease), slug, replaceFirst, replaceLast, start, and finish. So the honest framing is: this package is worth it only if you need the specific gaps — tease (word-boundary truncation with cleanup), possessive, and the segment/pop family — and you aren't already standardized on Str::of().
  • Not a roadmap item. Nothing here unblocks a feature, changes a customer-facing capability, or differentiates the product. It should never appear in a prioritization conversation as scope — it is a developer-ergonomics decision with an engineering-hours cost measured in minutes.
  • Ecosystem/standardization decision. If the team is already Spatie-heavy (image, permission, data-transfer-object, laravel-backup), this is a low-friction addition to a consistent mental model. If the team is intentionally minimizing dependencies, this fails the bar — it is trivially replaceable with ~150 lines of in-house code.

When to Consider This Package

Adopt when:

  • You have a concrete need for tease() (truncating user- or CMS-supplied text to a word boundary after stripping HTML and collapsing whitespace) or possessive() — these are genuinely fiddly to get right and the package's edge-case fixes (empty string, "it") are the kind of detail teams only discover in production.
  • You're manipulating URL-ish or path-ish strings with a fixed delimiter and want segment / firstSegment / lastSegment / pop inline rather than index arithmetic.
  • The codebase is small or young and the team would otherwise write its own fluent string wrapper. Adopting is cheaper than building and reviewing one.
  • You want chained string logic to read left-to-right in reviews: string($path)->pop('/')->lastSegment('/')->toLower() is easier to scrutinize than nested strtolower(substr(strrchr(...))).
  • PHP 8+ is guaranteed and you're comfortable with a single-maintainer, maintenance-mode utility.

Look elsewhere when:

  • You're on a modern Laravel version and already use Str::of(). The overlap is substantial; running two string APIs in one codebase is a readability cost with no offsetting benefit. Pick one and codify it in your style guide.
  • Anyone is tempted by the underscore.php passthrough (slugify() and friends). That dependency is a legacy artifact; use Str::slug() or Cocur\Slugify directly. Do not let this package become the reason an abandoned dependency is pulled in.
  • You need rich, differentiated behavior: multibyte/Unicode correctness guarantees, grapheme-aware slicing, case folding for locales (Turkish dotless i), transliteration breadth, or performance-tuned bulk transformation. This is not that package — it is a thin ergonomic wrapper, and toUpper() is not a Unicode strategy.
  • You require explicit support SLAs, vendor security review, or a formal maintenance commitment. This is a Spatie side-project in maintenance mode: the most recent release (3.0.1) is a code-style tooling swap, and the 3.x line was essentially "PHP 8 only, drop 7.x." Treat it as frozen, and be honest internally that a future PHP major may leave you forking it.
  • You want a framework-native facade, config, or container bindings. There are none, by design — it registers nothing and integrates with nothing.
  • The team is dependency-averse: this is a global string() helper function in a Laravel app that also has str(). Function-name collisions and two similarly-named APIs invite mistakes in code review.

Adoption guardrails: pin the version, isolate usage behind your own formatting/helper layer so swapping to Str::of() later is a single-file change, and forbid use of the underscore passthrough in new code.

How to Pitch It (Stakeholders)

To executives (one paragraph): "This is a small, free, MIT-licensed utility that makes common text formatting — truncating a description cleanly at a word boundary, turning 'Charles' into 'Charles'', pulling a segment out of a URL path — a single readable line of code instead of a hand-written helper. The cost is effectively zero: it's a couple of files, installs in one command, adds no configuration, no database change, and no runtime infrastructure, so it cannot affect uptime, performance, or an upgrade path. The only real decision is a housekeeping one — whether our engineers use this or the string helpers already built into Laravel. Our recommendation is to let engineering standardize on one of the two, not both, and to treat this as a code-quality nicety rather than a project. It does not change what we ship to customers or when."

To engineering (the substantive version): It's a thin String value object plus a string() helper — no service provider, no config, no publishing, no framework coupling. Architecturally inert: it can't break boot order, config caching, queue serialization, or a Laravel major upgrade, and it gains nothing from the framework either. It's a utility layer, never infrastructure. The real engineering conversation is overlap: Str::of() already gives you between, limit, slug, replaceFirst, replaceLast, start, and finish. What this package adds that Str does not is tease (HTML stripping + double-space cleanup + word-boundary truncation), possessive (with the awkward empty-string and "it" cases handled), and the segment / firstSegment / lastSegment / pop family for delimiter-based path work. Recommendation: if more than a couple of those gaps are live in our code, adopt it, pin it, and wrap it in our own formatter so a future swap is one file. If not, stay on Str and close the ticket. Either way, do not enable the bundled underscore.php passthrough — that pulls in a legacy dependency for slugify(), which Str::slug() already does. And plan on this being unmaintained-but-fine: latest release is a Pint swap, the 3.x line was just "PHP 8 only," and we should assume we may vendor a fork if a future PHP version breaks it. That's a ten-minute risk, not an architectural one.

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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator