mpietrucha/laravel-package
最新稳定版本:1.0.0
Composer 安装命令:
composer require mpietrucha/laravel-package
包简介
Laravel package tools.
README 文档
README
A powerful toolkit for Laravel package development that simplifies common package patterns including service provider setup, macro/mixin registration, context detection, and translation helpers.
Installation
Requires PHP 8.5+ and Laravel 12.37+
You can install the package via Composer:
composer require mpietrucha/laravel-package
Usage
Service Provider
Extend the ServiceProvider class for enhanced package configuration:
use Mpietrucha\Laravel\Package\ServiceProvider; use Mpietrucha\Laravel\Package\Builder; class MyPackageServiceProvider extends ServiceProvider { public function configure(Builder $package): void { $package ->name('my-package') ->hasConfigFile() ->hasViews() ->hasTranslations(); } }
Macros
Register macros with built-in error handling and validation:
use Mpietrucha\Laravel\Package\Macro; use Illuminate\Support\Collection; Macro::attach( destination: Collection::class, name: 'sum', handler: fn() => $this->reduce(fn($carry, $item) => $carry + $item, 0) );
Mixins
Register multiple methods at once using mixins:
use Mpietrucha\Laravel\Package\Mixin; use Illuminate\Support\Collection; // Using a trait trait CollectionHelpers { public function sumAll(): int { return $this->sum(); } public function avgAll(): float { return $this->avg(); } } Mixin::attach(Collection::class, CollectionHelpers::class); // Using an object class CollectionMixin { public function double() { return $this->map(fn($item) => $item * 2); } public function positive() { return $this->filter(fn($item) => $item > 0); } } Mixin::attach(Collection::class, new CollectionMixin());
Context Detection
Automatically detect information about your package:
use Mpietrucha\Laravel\Package\Context; $name = Context::name(); $directory = Context::directory(); $provider = Context::provider();
Translations
Use scoped translation helpers in your package:
use Mpietrucha\Laravel\Package\Translations\Concerns\InteractsWithTranslations; class MyClass { use InteractsWithTranslations; public function getMessage(): string { // Automatically scopes to 'my-package::messages.welcome' return static::__('messages.welcome'); } public function getGreeting(string $name): string { // Equivalent to __('my-package::messages.hello', ['name' => $name]) return static::__('messages.hello', ['name' => $name]); } }
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-22