定制 cnaebadi/null-replacer 二次开发

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

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

cnaebadi/null-replacer

最新稳定版本:v1.0.0

Composer 安装命令:

composer require cnaebadi/null-replacer

包简介

A Laravel validation rule to remove or replace null fields before validation.

README 文档

README

Null Replacer Logo

Null Replacer

A Laravel validation rule to automatically remove, replace, or convert null values in request data before validation.

Latest Version on Packagist Total Downloads License: MIT

✨ Features

  • Replace null values with a custom value
  • Convert 'true' and 'false' strings to actual boolean values
  • Remove null fields entirely from the request
  • Can be used directly in Form Request rules

🚀 Installation

composer require cnaebadi/null-replacer

🧪 Usage

⚠️ Note: When using null_replacer, you do not need to use nullable. This rule handles null values entirely on its own and using nullable before it may interfere with its functionality.

In your Laravel Form Request:

public function rules()
{
    return [
        'optional_note'  => ['null_replacer'], // Removes key if null
        'is_active'      => ['null_replacer:true'], // Converts to boolean true
        'email'          => ['null_replacer:default@example.com'], // Replaces null with given default
    ];
}

🛠 How It Works

  • null-replacer:true: 'true'/'false'true/false
  • null-replacer:something: replaces null with "something"
  • null-replacer (no value): removes the key from the request if it's null

📦 Publish & Extend

If you want to customize the behavior, you can publish the config (if added later) or extend the core rule logic in your own classes.

🧑‍💻 Author

Sina Ebadi

📄 License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

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