定制 sylarele/laravel-set 二次开发

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

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

sylarele/laravel-set

Composer 安装命令:

composer require sylarele/laravel-set

包简介

Set of interfaces, objects, and practices to standardise Laravel backends

README 文档

README

Set of interfaces, objects, and practices to standardise Laravel backends

Schedule list

Initialise your schedule directory

app/
└─ Schedule/
    ├─ Command/ # for $schedule->command
    └─ Job/     # for $schedule->job

Add your commands and jobs. Then return an anonymous class that inherits from Sylarele\LaravelSet\Contract\Console\ScheduleInterface.

<?php

declare(strict_types=1);

use App\Console\Command\AcmeCommand;
use Illuminate\Console\Scheduling\Schedule;
use Sylarele\LaravelSet\Contract\Console\ScheduleInterface;

return new class() implements ScheduleInterface
{
    public function handle(Schedule $schedule): void
    {
        $schedule->command(AcmeCommand::class)->dailyAt('08:00');
        /* [...] */
    }
};

Then declare your commands in the kernel

In Laravel 10

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Sylarele\LaravelSet\Service\ScheduleHandler;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        $scheduleHandler = new ScheduleHandler([
            base_path('app/Schedule/Command/*.php'),
            base_path('app/Schedule/Job/*.php'),
        ]);
        $scheduleHandler->handle($schedule);
    }
    
    /* [...] */
}

In Laravel >= 11

use Sylarele\LaravelSet\Service\ScheduleHandler;

->withSchedule(
    (new ScheduleHandler([
        dirname(__DIR__).'/app/Schedule/Command/*.php',
        dirname(__DIR__).'/app/Schedule/Job/*.php',
    ]))
    ->handle(...)
)

See the schedule list :

php artisan schedule:list

Media

Rules

When you need to manage multiple media types in your application, it is best to centralize the validation rules in your configuration.

Create an enumeration to list your files:

<?php
enum PublicFileType: string
{
    case FooImage = 'foo:image';
}

Create a file_rules.php and image_rules.php configuration file and declare your validation rules:

<?php
// config/file_rules.php

use Sylarele\LaravelSet\Media\Dto\Config\FileRuleConfigDto;

return [
    'rules' => [
        PublicFileType::FooImage->value => FileRuleConfigDto::fromImage(),
    ],
];

The rules available for your media are:

  • FileRuleConfigDto::fromImage(),
    • {min: 1kb, max: 400kb, mimes: ['png', 'jpg', 'jpeg', 'webp']}
  • FileRuleConfigDto::fromFile(),
    • {min: 1kb, max: 15mb, mimes: ['*']}
  • FileRuleConfigDto::fromPdf(),
    • {min: 1kb, max: 15mb, mimes: ['pdf']}
  • FileRuleConfigDto::fromDocument(),
    • {min: 1kb, max: 15mb, mimes: ['csv', 'doc', 'docx', 'pdf', 'png', 'jpg', 'jpeg', 'xls', 'xlsx', 'webp']}

You can also rewrite the rules according to your needs by filling in the input parameters.

<?php
// config/image_rules.php

use Sylarele\LaravelSet\Media\Dto\Config\ImageConfigDto;

return [
    'rules' => [
        PublicFileType::FooImage->value => new ImageConfigDto(
            resizeHeight: 300,
            resizeWidth: 300,
        ),
    ],
];

Declare your configurations in your provider:

<?php

use Sylarele\LaravelSet\Media\Service\FileRuleService;

public function register(): void
{
    $this->app
        ->when(FileRuleService::class)
        ->needs('$fileRulesConfig')
        ->giveConfig('file_rules.rules');
    $this->app
        ->when(FileRuleService::class)
        ->needs('$imagesConfig')
        ->giveConfig('image_rules.rules');
}

In your FormRequest, call your rule with the key from your file:

use Sylarele\LaravelSet\Media\Rule\FileRule;

public function rules(): array
{
    return [
        'image' => ['nullable', new FileRule(PublicFileType::FooImage)],
    ];
}

Modify the translation of the following rules to include the format:

return [
    'file_rules' => [
        'gt' => 'The :attribute field must be greater than :value :format.',
        'lt' => 'The :attribute field must be less than :value :format.',
        'unit' => [
            'kb' => 'Kb',
            'mb' => 'Mb',
            'gb' => 'Gb',
        ],
    ],
];

You can inform your fronts with an API endpoint using the service and resource provided by the package.

<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Enums\File\PublicFileType;
use Illuminate\Http\JsonResponse;
use Sylarele\LaravelSet\Media\Http\Resource\FileRuleResource;
use Sylarele\LaravelSet\Media\Service\FileRuleService;

class FileRuleController
{
    public function __construct(
        private readonly FileRuleService $fileRuleService
    ) {
    }

    public function index(): JsonResponse
    {
        $list = $this->fileRuleService->listByScope(PublicFileType::cases());

        return FileRuleResource::collection($list)->response();
    }
}

The following example will return the following JSON:

{
  "data": [
    {
      "name": "foo:image",
      "file_rule": {
        "type": "image",
        "mimes": [
          "png",
          "jpg",
          "jpeg",
          "webp"
        ],
        "size_min": {
          "size": 1,
          "unit": "kb",
          "bytes": 1000
        },
        "size_max": {
          "size": 400,
          "unit": "kb",
          "bytes": 400000
        }
      },
      "image_config": {
        "height": 100,
        "width": 100
      }
    }
  ]
}

sylarele/laravel-set 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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