rawnoq/laravel-form-data-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rawnoq/laravel-form-data-parser

Composer 安装命令:

composer require rawnoq/laravel-form-data-parser

包简介

A Laravel package for parsing multipart/form-data requests

README 文档

README

A professional Laravel package for parsing multipart/form-data requests, especially useful for handling PUT, PATCH, and DELETE requests with file uploads.

Installation

composer require rawnoq/laravel-form-data-parser

The package will be automatically discovered and registered by Laravel.

Features

  • ✅ Automatically parses multipart/form-data requests
  • ✅ Supports nested form fields with bracket notation (e.g., name[ar], name[en], items[0][name])
  • ✅ Handles file uploads in PUT/PATCH/DELETE requests
  • ✅ Converts flat keys to nested arrays automatically
  • ✅ Robust error handling and edge case support
  • ✅ Works seamlessly with Laravel's request handling
  • ✅ Compatible with Laravel 11+ and Laravel 12+
  • ✅ No configuration required

Usage

The package automatically registers a middleware that parses multipart/form-data requests. No configuration needed!

The middleware automatically:

  • Parses multipart/form-data content
  • Extracts form fields and files
  • Converts bracket notation to nested arrays
  • Makes data available via $request->input() and $request->file()

Example

// In your controller
public function update(Request $request)
{
    // Access form data
    $name = $request->input('name');
    $nameAr = $request->input('name.ar'); // Nested notation
    $itemName = $request->input('items.0.name'); // Array notation
    
    // Access files
    $avatar = $request->file('avatar');
    $documents = $request->file('documents'); // Array of files
    
    // Process your request...
}

Supported Form Field Formats

The package supports various form field formats:

// Simple fields
name=John

// Nested fields
name[ar]=جون
name[en]=John

// Array fields
items[0][name]=Item 1
items[1][name]=Item 2

// Mixed with files
avatar=file
name[ar]=جون

How It Works

The middleware intercepts requests with multipart/form-data content type and:

  1. Extracts the boundary from the request (multiple methods for reliability)
  2. Parses each part of the multipart data
  3. Identifies files vs regular form fields
  4. Creates temporary files for uploaded files
  5. Converts bracket notation to nested arrays
  6. Merges parsed data into the request object
  7. Handles errors gracefully without breaking the request

Supported Methods

The middleware processes requests for methods other than:

  • GET
  • HEAD
  • POST (Laravel handles this natively)

This means it works with:

  • PUT
  • PATCH
  • DELETE
  • And other custom methods

Error Handling

The package includes comprehensive error handling:

  • Invalid boundary detection with multiple fallback methods
  • File creation errors are caught and handled
  • Temporary file cleanup on errors
  • Graceful degradation - if parsing fails, the request continues normally
  • Debug logging in development mode

Requirements

  • PHP 8.2+
  • Laravel 11.0+ or Laravel 12.0+

🧪 Testing

The package comes with a comprehensive test suite:

# Run tests
composer test

# Run tests with coverage
composer test-coverage

Test Coverage

The test suite includes:

  • ✅ Form data parsing tests
  • ✅ Nested fields and bracket notation tests
  • ✅ File upload handling tests
  • ✅ Middleware integration tests
  • ✅ ServiceProvider registration tests
  • ✅ Error handling tests

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

rawnoq/laravel-form-data-parser 适用场景与选型建议

rawnoq/laravel-form-data-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「parser」 「middleware」 「laravel」 「multipart」 「form-data」 「file-upload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rawnoq/laravel-form-data-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rawnoq/laravel-form-data-parser 我们能提供哪些服务?
定制开发 / 二次开发

基于 rawnoq/laravel-form-data-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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