Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Extended Laravel Package

onursimsek/laravel-extended

Laravel Extended adds developer-friendly extensions to Laravel, including practical helpers, macros, and model/query conveniences that reduce boilerplate for common tasks. It stays lightweight and framework-native, making it easy to drop into existing apps.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package:

    composer require onursimsek/laravel-extended
    

    Laravel's package auto-discovery should register the service provider — confirm in bootstrap/providers.php (Laravel 11+) or config/app.php if you're on an older skeleton and the provider isn't listed.

  2. Read the package README first, then the test suite. For the 1.3.0 change specifically, PR #16 (Enum attributes can use as a function) is the authoritative source for the new call syntax — release notes are one line, so the tests are where the real contract lives.

  3. First use case: annotate enum cases with a PHP attribute carrying display metadata (label, colour, icon, description) and read it without hand-rolled ReflectionEnum code:

    enum Status: string
    {
        #[Label('Draft')]
        case Draft = 'draft';
    
        #[Label('Published')]
        case Published = 'published';
    }
    
  4. Before adopting the new callable form, run it against one enum in a scratch test to confirm the exact invocation shape in 1.3.0 — the release note does not pin down whether it's a method on the case, a static helper, or a trait-provided accessor.

Implementation Patterns

  • Attribute class definition. Keep attribute classes small and typed (public function __construct(public string $label) {}). Mark them #[Attribute(Attribute::TARGET_CLASS_CONSTANT)] so they attach to enum cases rather than enum classes.

  • Single accessor, not scattered reflection. Wrap the read in one place — a trait on the enum or a small resolver service — so the 1.3.0 callable syntax is isolated. If the API shifts in 1.4, you change one file instead of twenty.

  • Eloquent casts. Combine with native enum casting so the attribute metadata travels with the model value:

    protected $casts = ['status' => Status::class];
    

    Then $model->status yields the case and the attribute lookup is a single call away — useful in Blade ({{ $model->status->label() }}) and API resources.

  • Validation and form options. Derive <select> options and Rule::enum() friendly lists from the same attributes instead of a parallel config array. One definition, one source of truth.

  • Filament / Nova / admin panels. This is the strongest day-to-day win: colour and label metadata per case, resolved through the attribute layer, keeps admin config declarative.

  • Testing. Data-provider the enum cases and assert the attribute resolves for every case. A missing attribute on a newly added case is the most likely production bug; a test that iterates Status::cases() catches it at CI time.

  • Fallbacks. Always code a default when an attribute is absent (e.g. ?? Str::headline($case->name)), so adding a case without metadata degrades rather than throws.

Gotchas and Tips

  • Attribute arguments must be constant expressions. No __(), no config(), no service container access inside an attribute. If you need translations, store a translation key in the attribute and resolve it at read time.
  • TARGET_CLASS_CONSTANT vs TARGET_CLASS. Getting the target wrong means the attribute silently never appears where you expect. If lookups return nothing, check the #[Attribute] flags before anything else.
  • Repeatable attributes. If you want multiple attributes of the same class on one case, you must pass Attribute::IS_REPEATABLE; otherwise PHP throws at attribute-instantiation time, not at declaration time.
  • Reflection cost. newInstance() on attributes is not free. If you resolve metadata in a loop over large collections, memoise per-case results in a static array or a small cache.
  • Backward compatibility 1.2.1 → 1.3.0. This is a minor bump with an additive-sounding feature, so nothing should break — but "can use as a function" may have changed an accessor from a property/magic-get to a real method. If you were reading attributes through the previous API, grep your codebase for those call sites and re-run the suite.
  • Method/attribute name collisions. If your attribute is named Label and your enum already has a label() method, the callable form can shadow or be shadowed depending on resolution order. Prefer distinct names (#[DisplayLabel]) or suffix the accessor.
  • Static analysis and IDE support. PHPStan/Psalm understand enum cases but often not dynamic attribute resolution; expect to add @method annotations or a stub on the trait to keep autocompletion and level-8 analysis clean.
  • Serialisation. Attributes are compile-time metadata, not state — they won't survive json_encode of an enum. Resolve to a plain array/scalar in your API resource layer rather than passing enum cases around.
  • Pin the version and watch the changelog. The package is young (1.3.0) and the release notes are terse. Lock the minor version in composer.json and read the diff — not just the summary — before each upgrade.
  • Debugging entry point. When an attribute lookup misbehaves, drop to (new ReflectionEnum(Status::class))->getCase('Draft')->getAttributes() and inspect raw reflection output; that immediately separates "attribute not attached" from "package resolver not finding it".
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel