PHPackages                             ferdinandbr/laravel-model-unique-field - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. ferdinandbr/laravel-model-unique-field

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

ferdinandbr/laravel-model-unique-field
======================================

create a record with a unique field without worrying

v1.0.0(1y ago)13MITPHPPHP &gt;=7.3

Since Oct 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ferdinandbr/laravel-model-unique-field)[ Packagist](https://packagist.org/packages/ferdinandbr/laravel-model-unique-field)[ RSS](/packages/ferdinandbr-laravel-model-unique-field/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Simple way to handle dynamically unique fields in Laravel models
================================================================

[](#simple-way-to-handle-dynamically-unique-fields-in-laravel-models)

The ferdinandbr/laravel-model-unique-field package provides a simple way to handle dynamically unique fields in Laravel models. When creating or updating a model with a field that needs to be unique, the package automatically appends a numeric suffix if a duplicate value is detected. This allows you to easily manage unique fields like names, serial numbers, or other attributes without manually checking for duplicates.

For example, if a model is created with a name "Product A" and another model is created with the same name, the second model’s name will automatically be "Product A #2", and so on. This feature is especially useful when dealing with large datasets, imports, or batch operations where conflicts might occur.

The package is customizable and can be applied to any model attribute, ensuring smooth management of unique field values across your application.

Requirement
-----------

[](#requirement)

- Minimum PHP ^8.0

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

[](#installation)

You can install the package via composer for latest version

```
composer require ferdinandbr/laravel-model-unique-field
```

Quick usage
-----------

[](#quick-usage)

Add UniqueField trait to model and add $dynamicField to field referencing the column you want the value to not be repeated

```
use Ferdinandbr\LaravelModelUniqueField\Traits\UniqueField;

class TestModel extends Model
{
    use UniqueField;

    protected $dynamicField = 'name';

}
```

Examples
========

[](#examples)

```
use App\Models\Product;

$product1 = Product::create(['name' => 'Widget']);
$product2 = Product::create(['name' => 'Widget']);
$product3 = Product::create(['name' => 'Widget']);

echo $product1->name; // Output: "Widget"
echo $product2->name; // Output: "Widget #2"
echo $product3->name; // Output: "Widget #3"

use App\Models\Device;

$device1 = Device::create(['serial_number' => 'SN123']);
$device2 = Device::create(['serial_number' => 'SN123']);
$device3 = Device::create(['serial_number' => 'SN123']);

echo $device1->serial_number; // Output: "SN123"
echo $device2->serial_number; // Output: "SN123 #2"
echo $device3->serial_number; // Output: "SN123 #3"
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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

588d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0826992345ebd04b505e09511f2f68de1452f324d8042778124670b0a0ad2f36?d=identicon)[ferdinandbr](/maintainers/ferdinandbr)

---

Top Contributors

[![ferdinandbr](https://avatars.githubusercontent.com/u/35705085?v=4)](https://github.com/ferdinandbr "ferdinandbr (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/ferdinandbr-laravel-model-unique-field/health.svg)

```
[![Health](https://phpackages.com/badges/ferdinandbr-laravel-model-unique-field/health.svg)](https://phpackages.com/packages/ferdinandbr-laravel-model-unique-field)
```

###  Alternatives

[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1036.7k3](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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