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

Nova Belongs To Badge Laravel Package

lifeonscreen/nova-belongs-to-badge

A Laravel Nova field that displays a belongsTo relationship as a compact, color-coded badge in index and detail views, so related records are easy to scan at a glance. Simple to configure with custom labels, colors, and value mappings.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package with Composer and run any migrations/config publish steps listed in its README. v1.0.0 is the first stable release, so treat the install docs as the source of truth and pin the major version (^1.0).
  2. Look first at the package's service provider and the Eloquent model/trait it exposes. Confirm which relationships are now eager-loadable and whether they are standard HasOne/HasMany/BelongsTo/morphTo relations.
  3. First use case: take an existing query that loops over parent models and accesses a package-provided relation inside the loop, then add ->with('packageRelation') and verify the query count drops. Eager loading is the headline v1.0.0 feature, so this is the quickest way to validate the upgrade.

Implementation Patterns

  • Query-time eager loading: Parent::with('packageRelation')->get() is the default pattern for list/index endpoints. Add constraints with closures: with(['packageRelation' => fn ($q) => $q->where('active', 1)]).
  • Nested relations: with('packageRelation.child') avoids N+1 at deeper levels, especially when API resources serialize nested data.
  • Lazy eager loading in controllers: use $parent->load('packageRelation') after route-model binding, and loadMissing('packageRelation') when the relation may already be loaded by a parent query.
  • API resources: guard optional relations with whenLoaded('packageRelation') so serialization never triggers an implicit lazy load and the eager-loading contract stays explicit.
  • Default eager loads: if the package's model supports a $with property, use it only for relations that are needed on virtually every query. Prefer explicit with() for everything else to avoid over-fetching.
  • Aggregates: use withCount('packageRelation') or withSum when you only need a count/sum; loading the full relation is wasted work.
  • Large datasets: eager load per chunk (chunkById(..., fn ($parents) => $parents->load('packageRelation'))) rather than loading everything at once.
  • Testing: assert query counts with DB::enableQueryLog() or Laravel's query-count expectations to lock in the eager-loading behavior and catch regressions.

Gotchas and Tips

  • select() can break eager loading. If you restrict columns, include the foreign keys the relation needs, or the relation silently resolves to empty collections.
  • Lazy loading still happens by default. Enable Model::preventLazyLoading(! app()->isProduction()) to catch places where the new eager loading support is not being used.
  • load vs loadMissing: load re-queries and overwrites; loadMissing is a no-op if the relation is already present. Use loadMissing in shared code paths and load after explicit refreshes.
  • Stale relations: after refresh(), mass updates, or model events that change related records, eager-loaded relations can be out of date. Reload explicitly when correctness matters.
  • Constrained eager loads on morphTo: closures behave differently for polymorphic relations; use morphWith/morphWithCount where applicable.
  • Huge relations: eager loading a HasMany with thousands of rows is often worse than a targeted query. Prefer withCount, latestOfMany, or a separate paginated query.
  • Config quirks: check whether v1.0.0 adds an eager-loading config flag or allowlist in config/; publishing config is often required to change defaults.
  • Extension points: custom relationship methods, local scopes, relationship closures, and the model's $with property are the safest customization surfaces. Avoid overriding package internals; hook through scopes and model events instead.
  • Upgrade posture: v1.0.0 has no deprecations to track yet, but watch the changelog for 1.x breaking changes before widening the version constraint.
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.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin