定制 sumaiazaman/laravel-stringable-extras 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sumaiazaman/laravel-stringable-extras

Composer 安装命令:

composer require sumaiazaman/laravel-stringable-extras

包简介

Missing whenDoesntContain and whenDoesntContainAll methods for Laravel's Stringable class.

README 文档

README

Latest Version on Packagist Tests License

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固