upline/row-background
A small Laravel package for adding alternating row background colors to tables and lists, with configurable shades and Blade-friendly helpers to keep data-heavy views readable at a glance.
This field paints a Nova resource's index rows a given background color, which makes it a pure presentational field — it does not persist anything itself. Get it in place in three steps:
composer require upline/row-background. Since the package has 0 stars and 0 dependents, pin the version explicitly ("upline/row-background": "1.*") and read src/ before shipping to production. There is no ecosystem of examples to lean on, so the source is your documentation.fields() method, typically near the top so it reads clearly:
use Upline\RowBackground\RowBackground;
public function fields(Request $request)
{
return [
RowBackground::make()->color(fn ($model) => $model->status->color()),
ID::make()->sortable(),
// ...
];
}
The field resolves a color string (hex or CSS color) per row; how that resolution is wired exactly (->color(), a model attribute, withMeta()) is the first thing to confirm in the package source — it's small enough to read in a few minutes.If your Nova version isn't explicitly supported in composer.json, test a single resource before rolling it out across a panel.
Derive the color, don't store it. The field is a view concern; keep the source of truth in an enum, accessor, or cast. A clean pattern:
enum TicketStatus: string
{
public function rowColor(): string
{
return match($this) {
self::Open => '#dbeafe',
self::Overdue => '#fee2e2',
self::Closed => '#e5e7eb',
};
}
}
Then RowBackground::make()->color(fn ($ticket) => $ticket->status->rowColor()). Colors stay testable and versionable.
Fallback for null/missing values. Always guard: fn ($m) => $m->status?->rowColor() ?? 'transparent'. Without a fallback, a null status can leave the row with an empty or unexpected background and you'll chase a "broken" row that's really just unset data.
Conditional highlighting for at-a-glance triage. The strongest day-to-day use is surfacing outliers: overdue invoices red, unassigned items amber, healthy rows neutral. Combine with a Badge on the same column so the color is reinforced by text — never rely on color alone for meaning (accessibility and color-blind users).
Compute once, avoid accessor overhead. If the color depends on a query (e.g. counts, relations), the field callback runs per row during index rendering. On a 50-row index that's 50 evaluations — fine — but if each one hits the database you're building an N+1. Push the logic into indexQuery() with eager loading or a withCount, and make the callback a cheap read on already-loaded data.
Keep the color rules in one class. For panels with many resources, a small RowColorPalette service (or enum trait) beats scattering hex codes across resources. When the design team changes the palette, you edit one file.
Don't overload it. It's tempting to encode urgency, category, and SLA state into one row color. Pick one dimension per resource; anything more becomes noise and the colors stop conveying anything.
meta()/withMeta() payload is the first place to look.composer.json constraints against your Nova major version and smoke-test the index view; silent breakage (field renders, no color applied) is the most likely failure mode.#dbeafe reads well on white but can look washed out or glare on Nova's dark theme. If you support dark mode, keep backgrounds light enough for dark text or verify text stays legible — the field usually only controls background, not foreground.make() argument matches a real column, Nova may treat it as an actual attribute in search/sort contexts. Use a presentation-only name (row_background) or omit sorting; a display field shouldn't be sortable.fields(), not just indexFields(), (b) the callback returns a non-null string for at least some rows, (c) the value isn't being overridden by a later field or resource-level styling, and (d) the emitted meta reaches the frontend — php artisan nova:check / browser console on the index route.How can I help you explore Laravel packages today?