定制 laragear/meta 二次开发

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

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

laragear/meta

Composer 安装命令:

composer require laragear/meta

包简介

A Laravel Package helper for Laravel Packages

README 文档

README

Latest Version on Packagist Latest stable test run Codecov Coverage Maintainability Sonarcloud Status Laravel Octane Compatibility

A Laravel Package helper for Laravel Packages.

public function boot()
{
    $this->withPublishableMigrations(__DIR__.'/../migrations');
    
    $this->withSchedule(fn($schedule) => $schedule->command('inspire')->hourly());
}

Become a sponsor

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word in social media.

Requirements

  • PHP 8.3 or later
  • Laravel 12 or later.

Installation

Require this package into your project using Composer:

composer require laragear/meta

Package testers

You may additionally install testing helpers for your package. These should be installed in your require-dev arm of your composer so these are not shipped in the production version of your package.

composer require --dev laragear/meta-testing

Discoverer

The Discover class is a builder that allows discovering classes under a given path. It contains various fluent methods to filter the classes to discover, like methods, properties, interfaces and traits, among others.

composer require laragear/discover

Middleware declaration

When using withMiddleware() you will receive a MiddlewareDeclaration object with convenient methods to register the middleware globally or inside a group, set it as first/last in the global priority stack, and register an alias for it.

public function boot()
{
    $declaration = $this->withMiddleware(OnlyAdults::class);
    
    // Make it a shared instance.
    $declaration->shared();
    
    // Set an alias
    $declaration->as('adults');
    
    // Puts it inside a middleware group.
    $declaration->inGroup('web');
    
    // Sets the middleware in the global stack.
    $declaration->globally();
    
    // Makes the middleware run first or last in the priority stack.
    $declaration->first();
    $declaration->last();
}

Builder extender

The ExtendsBuilder trait allows a Global Scope to extend the instance of the Eloquent Builder with new methods. Simply start your builder methods extend, no matter wich visibility scope or if the method is static or not.

use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Laragear\Meta\Database\Eloquent\ExtendsBuilder;

class Cars implements Scope
{
    use ExtendsBuilder;
    
    public function apply(Builder $builder, Model $model)
    {
        // ...
    }
    
    private function extendWhereAvailable($builder)
    {
        return $builder->where('available_at', '>', now());
    }
    
    protected static function extendWhereColor($builder, string $color)
    {
        return $builder->where('base_color', $color);
    }
}

Tip

If you need the model being queried, you can always use getModel() over the Eloquent Builder instance.

Command Helpers

This meta-package includes the WithEnvironmentFile helper trait to modify the environment file keys and values.

use Illuminate\Console\Command;
use Laragear\Meta\Console\Commands\WithEnvironmentFile;

class AddServiceKey extends Command
{
    use WithEnvironmentFile;
    
    public function handle()
    {
        // ...
        
        $this->putEnvKey('AWESOME_SERVICE', $this->argument('service_key'))
    }
}

Attribute extractor

The package contains the Attr helper that receives a target class, object, function, and allows to retrieve all or one attribute. Better yet, you can directly call a method or retrieve an attribute property.

use Laragear\Meta\Attr;use Vendor\Package\Attributes\MyCustomAttribute;

#[MyCustomAttribute(color: 'blue')]
class Car
{
    // 
}

$car = new Car;

echo Attr::of($car)->get(MyCustomAttribute::class, 'color'); // "blue"

Laravel Octane compatibility

  • There are no singletons using a stale application instance.
  • There are no singletons using a stale config instance.
  • There are no singletons using a stale request instance.
  • ExtendsBuilder only initializes its static property once per Scope.

There should be no problems using this package with Laravel Octane.

Security

If you discover any security related issues, please email darkghosthunter@gmail.com instead of using the issue tracker.

License

This specific package version is licensed under the terms of the MIT License, at time of publishing.

Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2025 Laravel LLC.

laragear/meta 适用场景与选型建议

laragear/meta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 948.49k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2022 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 laragear/meta 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-22