定制 mpyw/laravel-file-errors 二次开发

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

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

mpyw/laravel-file-errors

Composer 安装命令:

composer require mpyw/laravel-file-errors

包简介

A tiny extension that reports validation error details about uploaded files

README 文档

README

A tiny extension that reports validation error details about uploaded files

Requirements

  • PHP: ^8.2
  • Laravel: ^11.0 || ^12.0 || ^13.0

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing

1. Install package

composer require mpyw/laravel-file-errors

2. Customize translation

Edit lang/{en,ja,...}/validation.php in your project.
Feel free to copy from lang.

<?php

use Mpyw\LaravelFileErrors\UploadError as Err;

return [
    /*
    |--------------------------------------------------------------------------
    | Validation Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines contain the default error messages used by
    | the validator class. Some of these rules have multiple versions such
    | as the size rules. Feel free to tweak each of these messages here.
    |
    */

    /* ... */

    // 'uploaded' => 'The :attribute failed to upload.',
    'uploaded' => [
        Err::TITLE_INI_SIZE => 'The :attribute exceeds the maximum filesize defined in the server.',
        Err::TITLE_FORM_SIZE => 'The :attribute exceeds the maximum filesize defined in the form.',
        Err::TITLE_PARTIAL => 'The :attribute was only partially uploaded.',
        Err::TITLE_NO_FILE => 'The :attribute was not uploaded.',
        Err::TITLE_CANT_WRITE => 'The :attribute could not be written on disk.',
        Err::TITLE_NO_TMP_DIR => 'The :attribute could not be uploaded; missing temporary directory.',
        Err::TITLE_EXTENSION => 'The :attribute upload was stopped by a PHP extension.',
        Err::TITLE_UNKNOWN => 'The :attribute could not be uploaded due to an unknown error.',
    ],

    /* ... */
];

Basic Usage

Important

The default implementation is provided by ValidationServiceProvider, however, package discovery is not available. Be careful that you MUST register it in config/app.php by yourself.

<?php

return [

    /* ... */

    'providers' => [
        /* ... */

        Mpyw\LaravelFileErrors\ValidationServiceProvider::class,

        /* ... */
    ],

];
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class UserController extends Controller
{
    public function update(Request $request)
    {
        $validator = Validator::make(
            $request->all(),
            [
                'name' => 'required|max:20',
                'avatar' => 'required|image',
            ]
        );

        // This may contain...
        //   ['avatar' => ['The avatar exceeds the maximum filesize defined in the server.']]
        dump($validator->errors()->toArray());
    }
}

Advanced Usage

Tip

You can extend Validator with IncludesFileErrorDetails trait by yourself.

<?php

namespace App\Providers;

use App\Services\Validation\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator as Validation;

class ValidationServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Validation::resolver(function (...$parameters) {
            return new Validator(...$parameters);
        });
    }
}
<?php

namespace App\Services\Validation;

use Illuminate\Validation\Validator as BaseValidator;
use Mpyw\LaravelFileErrors\IncludesFileErrorDetails;

class Validator extends BaseValidator
{
    use IncludesFileErrorDetails;

    /* ... */
}

mpyw/laravel-file-errors 适用场景与选型建议

mpyw/laravel-file-errors 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.01k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mpyw/laravel-file-errors 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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