Weave Code
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

Fluent string handling for PHP. Wrap strings with string() to get a chainable object with helpers like between(), case conversion, concatenation, and array-offset access for reading/updating characters. Lightweight utility by Spatie, installable via Composer.

View on GitHub
Deep Wiki
Context7

String handling evolved

Frequently asked questions about String
How do I install spatie/string in a Laravel project?
Run `composer require spatie/string` in your project root. No additional configuration is needed—just wrap strings with `string()` to start using the fluent API immediately.
Does spatie/string work with Laravel 10+ and PHP 8.2?
Yes, the package supports PHP 8+ and is fully compatible with Laravel 10+. It leverages PHP 8 features like typed properties, so ensure your Laravel app uses strict types for optimal integration.
Can I use spatie/string in Blade templates?
Absolutely. Use `@php` directives to chain methods, like `@php echo string($post->title)->tease(50) @endphp`, or create custom Blade components wrapping the fluent API.
How does spatie/string handle multibyte characters (e.g., 'café')?
Most methods (e.g., `slugify()`, `tease()`) support multibyte characters, but edge cases like locale-specific rules may require manual adjustments. Test with non-ASCII strings in your test suite.
Will spatie/string slow down my Laravel application?
No, the package is lightweight (~1MB) and optimized for performance. Avoid bulk operations (e.g., processing 10K+ strings) without benchmarking, but it’s safe for typical use cases like UI text formatting.
Can I extend spatie/string with custom methods (e.g., `formatCurrency()`)?
Yes, you can subclass the `String` class or use traits to add domain-specific methods. Document these extensions to avoid conflicts with future updates.
Does spatie/string replace Laravel’s built-in `Str` helper?
No, it’s a supplement. Use `spatie/string` for fluent chaining (e.g., `string()->slugify()->toUpper()`) and Laravel’s `Str` for simple operations (e.g., `Str::upper()`). They coexist seamlessly.
How do I test spatie/string in Laravel’s PHPUnit suite?
Add test cases for edge cases like empty strings, multibyte characters, and method chaining. Use Laravel’s `RefreshDatabase` trait if testing Eloquent model accessors with formatted strings.
What happens if I pass an empty string to methods like `possessive()`?
Some methods throw exceptions on empty input. Validate strings with `if (!empty($string))` or use `string($string)->isEmpty()` to handle edge cases gracefully.
Are there alternatives to spatie/string for Laravel?
Yes, consider `str` (by Laravel itself) for basic operations or `mattstauffer/stringy` for more advanced features. However, `spatie/string` stands out for its fluent API and Laravel-native integration.
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle