sumaiazaman/laravel-stringable-extras
Composer 安装命令:
composer require sumaiazaman/laravel-stringable-extras
包简介
Missing whenDoesntContain and whenDoesntContainAll methods for Laravel's Stringable class.
README 文档
README
Adds the missing whenDoesntContain() and whenDoesntContainAll() methods to Laravel's fluent Stringable class.
Laravel ships with whenContains() and whenContainsAll(), and has negative counterparts for start/end (whenDoesntStartWith, whenDoesntEndWith), but the negative counterpart for contains was never added to the framework. This package fills that gap.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
Installation
composer require sumaiazaman/laravel-stringable-extras
The service provider is auto-discovered — no manual registration needed.
Usage
whenDoesntContain()
Executes the callback when the string does not contain the given substring. Accepts a string or an array of strings (any match counts).
// Callback fires — string doesn't contain 'xxx' $result = str('hello world') ->whenDoesntContain('xxx', fn ($s) => $s->upper()); // 'HELLO WORLD' // Callback is skipped — string contains 'world' $result = str('hello world') ->whenDoesntContain('world', fn ($s) => $s->upper()); // 'hello world' // With a default callback $result = str('hello world') ->whenDoesntContain( 'world', fn ($s) => $s->upper(), fn ($s) => $s->title(), ); // 'Hello World' // Array of needles — callback fires only if none are present $result = str('hello world') ->whenDoesntContain(['foo', 'bar'], fn ($s) => $s->upper()); // 'HELLO WORLD'
whenDoesntContainAll()
Executes the callback when the string does not contain all of the given substrings. If even one needle is missing, the callback fires.
// Callback fires — 'xxx' is not in the string $result = str('hello world') ->whenDoesntContainAll(['hello', 'xxx'], fn ($s) => $s->upper()); // 'HELLO WORLD' // Callback is skipped — both needles are present $result = str('hello world') ->whenDoesntContainAll(['hello', 'world'], fn ($s) => $s->upper()); // 'hello world'
Testing
composer test
License
MIT. See LICENSE.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-22