PHPackages                             danjohnson95/eloquent-colours - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. danjohnson95/eloquent-colours

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danjohnson95/eloquent-colours
=============================

A helper for dealing with colours in Eloquent models

v0.0.1(3mo ago)04MITPHPPHP ^8.3

Since Feb 15Pushed 3mo agoCompare

[ Source](https://github.com/danjohnson95/eloquent-colours)[ Packagist](https://packagist.org/packages/danjohnson95/eloquent-colours)[ RSS](/packages/danjohnson95-eloquent-colours/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Eloquent Colours
================

[](#eloquent-colours)

A Laravel package for handling hex colour values in Eloquent models with validation and type safety.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require danjohnson95/eloquent-colours
```

The service provider will be automatically registered.

Requirements
------------

[](#requirements)

- PHP ^8.3
- Laravel ^12.0

Usage
-----

[](#usage)

### Migration

[](#migration)

Use the `colourRgb()` Blueprint macro to add a colour column to your migration:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->colourRgb('primary_color');
            $table->colourRgb('secondary_color')->nullable();
            $table->timestamps();
        });
    }
};
```

This creates a string column with a length of 7 characters (for `#RRGGBB` format).

### Model

[](#model)

Use the `Colour` cast in your Eloquent model to automatically validate and handle hex colour values:

```
namespace App\Models;

use DanJohnson95\EloquentColours\Casts\Colour;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name',
        'primary_color',
        'secondary_color',
    ];

    protected function casts(): array
    {
        return [
            'primary_color' => Colour::class,
            'secondary_color' => Colour::class,
        ];
    }
}
```

### Working with Colours

[](#working-with-colours)

```
// Create a product with a colour
$product = Product::create([
    'name' => 'Widget',
    'primary_color' => '#FF5733',
]);

// Access the colour value
echo $product->primary_color; // #FF5733

// Update the colour
$product->update([
    'primary_color' => '#3498DB',
]);

// The cast validates hex values automatically
$product->primary_color = '#INVALID'; // Throws InvalidArgumentException
```

### Colour Entity

[](#colour-entity)

You can also work with the `Colour` entity directly:

```
use DanJohnson95\EloquentColours\Entities\Colour;

// Create a colour from hex
$colour = Colour::makeFromHex('#FF5733');

// Validate hex values
Colour::isValidHex('#FF5733'); // true
Colour::isValidHex('FF5733');  // true (# is optional)
Colour::isValidHex('#XYZ123'); // false

// Convert to string
echo $colour; // #FF5733
echo $colour->hex; // #FF5733
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see the LICENSE file for more information.

Author
------

[](#author)

Dan Johnson -

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance82

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

92d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6871504?v=4)[Dan](/maintainers/danjohnson95)[@danjohnson95](https://github.com/danjohnson95)

---

Top Contributors

[![danjohnson95](https://avatars.githubusercontent.com/u/6871504?v=4)](https://github.com/danjohnson95 "danjohnson95 (6 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/danjohnson95-eloquent-colours/health.svg)

```
[![Health](https://phpackages.com/badges/danjohnson95-eloquent-colours/health.svg)](https://phpackages.com/packages/danjohnson95-eloquent-colours)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
