laravel-validation-rules/colour
Laravel validation rules for colour values. Validate CSS colour formats such as hex, RGB, RGBA, HSL and HSLA, plus named colours, using simple rule objects you can drop straight into form requests and validators.
Architecture fit
This is a single-purpose, dependency-light Laravel package that ships custom Rule objects (e.g. LVR\Colour\Hex, Rgb, Rgba, Hsl, Hsla, and named-colour variants) implementing Illuminate\Contracts\Validation\Rule. It slots into the framework's existing validation pipeline with no service provider bootstrapping, no config surface, and no persistence, queues, or I/O. Architecturally it is a leaf-node utility: it adds a regex-backed predicate to a form request and nothing else. Fit is high if our product actually ingests colour values from user input (theme/branding settings, category labels, calendar colours, chart configs); it is zero-value if colours are system-defined.
Integration feasibility
Trivially feasible. composer require laravel-validation-rules/colour, then instantiate the rule inside a FormRequest or inline validator. Effort is measured in minutes for a competent Laravel developer. The only real integration decision is where the rule applies: request-level validation only, or paired with a normalisation step (the package validates a format; it does not canonicalise to a single stored representation).
Technical risk
<style> blocks. If the accepted grammar is looser than intended, a "valid" colour becomes a CSS-injection vector. The rule must be treated as a security boundary, not a UX nicety, and output should be escaped regardless.rgb( forms).rgb(0 0 0 / 50%) modern syntax, 3- vs 6-digit hex, transparency keywords), producing user-facing validation errors that look like defects.Key questions
%, space-separated modern syntax, named colours)?Stack fit Native fit for a Laravel monolith or modular Laravel service using FormRequests and Laravel's validator. It is inert in non-Laravel contexts and should not be pulled into shared PHP libraries or domain packages — keep it in the HTTP/validation layer so the domain model is not coupled to a third-party rule class. If we have a colour value object, the rule belongs at the boundary and the value object should accept a normalised string.
Migration path
Greenfield: add directly to the relevant FormRequests. Brownfield: locate existing ad-hoc regex: rules and in: allowlists for colour fields, and consolidate them onto the package (or the in-house equivalent) behind tests that assert the same accept/reject corpus. Treat the consolidation as a small refactor with a documented before/after input corpus, so a later swap is mechanical.
Compatibility
Verify composer.json constraints against our PHP/Laravel matrix before committing; expect to need a fork (bump constraints, run the suite) if we are on a recent Laravel major. Pin to an exact version or a commit hash and record the pin rationale. Because the package is dev-tested against an older framework line, add our own feature tests for every accepted format rather than trusting upstream coverage.
Sequencing
Rule using the same tests — the exit is cheap and removes the maintenance question.Maintenance Near-zero runtime maintenance: no daemons, no config, no migrations, no scheduled work. The only recurring cost is dependency hygiene — reviewing the pin at each Laravel major upgrade and deciding to bump, fork, or replace. Budget roughly one hour per framework upgrade cycle.
Support Support surface is confined to "why was my colour rejected?" tickets. Mitigate by surfacing accepted formats in the field's helper text and returning a clear validation message. Internal support load is low; external community support does not exist (33 stars), so we are effectively self-supporting and should plan accordingly.
Scaling No scaling dimension. Validation is O(length of input) per field, executed in-process; negligible against any realistic request volume. No shared state, no contention, no cold-start behaviour. Horizontal scaling characteristics are identical to the host application.
Failure modes
Ramp-up Very low — a Laravel developer reads the README and is productive in under 15 minutes; the total knowledge footprint is one line in a FormRequest plus the acceptance grammar. The real ramp-up investment is the shared organisational decision about which colour formats are canonical, which is design work, not package work. Given the tiny surface area and easy substitutability, I would classify this as an adopt-and-vendor: use it to avoid writing regexes, but treat it as owned code with a documented fallback rather than a trusted long-term dependency.
How can I help you explore Laravel packages today?