PHPackages                             spoorsny/laravel-south-african-id - 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. [Database &amp; ORM](/categories/database)
4. /
5. spoorsny/laravel-south-african-id

ActiveLibrary[Database &amp; ORM](/categories/database)

spoorsny/laravel-south-african-id
=================================

Validation rules and an Eloquent Model attribute cast to value object encapsulating a South African government-issued personal identification number, for Laravel.

v1.2.0(1y ago)0375↑44.4%[1 issues](https://github.com/spoorsny/laravel-south-african-id/issues)GPL-3.0-or-laterPHPPHP ^8.3

Since Aug 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/spoorsny/laravel-south-african-id)[ Packagist](https://packagist.org/packages/spoorsny/laravel-south-african-id)[ RSS](/packages/spoorsny-laravel-south-african-id/feed)WikiDiscussions master Synced 1mo ago

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

[![Repository+Banner](https://camo.githubusercontent.com/1ea108b89857d6450b7b38aaaab922c207a906c454082c828e60c921d0f219ec/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f536f7574682532304166726963616e2532304944253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73706f6f72736e792532466c61726176656c2d736f7574682d6166726963616e2d6964267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d56616c69646174696f6e2b72756c65732b616e642b616e2b456c6f7175656e742b4d6f64656c2b6174747269627574652b636173742b746f2b76616c75652b6f626a6563742b656e63617073756c6174696e672b612b536f7574682b4166726963616e2b676f7665726e6d656e742d6973737565642b706572736f6e616c2b6964656e74696669636174696f6e2b6e756d6265722c2b666f722b4c61726176656c2e266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/1ea108b89857d6450b7b38aaaab922c207a906c454082c828e60c921d0f219ec/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f536f7574682532304166726963616e2532304944253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73706f6f72736e792532466c61726176656c2d736f7574682d6166726963616e2d6964267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d56616c69646174696f6e2b72756c65732b616e642b616e2b456c6f7175656e742b4d6f64656c2b6174747269627574652b636173742b746f2b76616c75652b6f626a6563742b656e63617073756c6174696e672b612b536f7574682b4166726963616e2b676f7665726e6d656e742d6973737565642b706572736f6e616c2b6964656e74696669636174696f6e2b6e756d6265722c2b666f722b4c61726176656c2e266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![Latest Version on Packagist](https://camo.githubusercontent.com/83ac1a12c03ed4681848c3a750fd539186f3bbaea0436d6b431094f421921f0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73706f6f72736e792f6c61726176656c2d736f7574682d6166726963616e2d69642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spoorsny/laravel-south-african-id)[![Total Downloads](https://camo.githubusercontent.com/de2c78b952e8d52a668dc180401074bb1ca94836661247f05c79410209e3e24c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73706f6f72736e792f6c61726176656c2d736f7574682d6166726963616e2d69642e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/de2c78b952e8d52a668dc180401074bb1ca94836661247f05c79410209e3e24c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73706f6f72736e792f6c61726176656c2d736f7574682d6166726963616e2d69642e7376673f7374796c653d666c61742d737175617265)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e9501a33401f2d805704b9429c1c6ce4987a4b4b4f659e42c1ef5c401185a660/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73706f6f72736e792f6c61726176656c2d736f7574682d6166726963616e2d69642f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/spoorsny/laravel-south-african-id/actions?query=workflow%3Acontinuous-integration+branch%3Amaster)[![PHPUnit Code Coverage](https://github.com/spoorsny/laravel-south-african-id/raw/image-data/coverage.svg)](https://github.com/spoorsny/laravel-south-african-id/actions?query=workflow%3Acontinuous-integration+branch%3Amaster)

South African ID for Laravel
============================

[](#south-african-id-for-laravel)

Validation rules and an Eloquent Model attribute cast to value object encapsulating a South African government-issued personal [identification number](https://www.westerncape.gov.za/general-publication/decoding-your-south-african-id-number-0), for Laravel.

The validator will pass values generated by the Faker [idNumber](https://fakerphp.org/locales/en_ZA/#fakerprovideren_zaperson)formatter that is part of the English (South Africa) or `en_ZA` locale.

Install
-------

[](#install)

Use [Composer](https://getcomposer.org) to install the package.

```
composer require spoorsny/laravel-south-african-id
```

Usage
-----

[](#usage)

### Validation Rules

[](#validation-rules)

A value submitted in a request can be validated to be a South African ID.

```
use Spoorsny\Laravel\Rules\SouthAfricanId;

$request->validate([
    'id_number' => ['required', 'string', new SouthAfricanId()],
]);
```

If the request also contains a birth date field, that field can be validated to match the South African ID using the `BirthDateMatchSouthAfricanId` rule. In this case, the field containing the South African ID, must be named `south_african_id`.

```
use Spoorsny\Laravel\Rules\BirthDateMatchSouthAfricanId;
use Spoorsny\Laravel\Rules\SouthAfricanId;

$request->validate([
    'south_african_id' => ['required', 'string', new SouthAfricanId()],
    'birth_date' => [
        'date_format:Y-m-d',
        'before_or_equal:today',
        new BirthDateMatchSouthAfricanId()
    ],
]);
```

### Cast

[](#cast)

An attribute of an [Eloquent](https://laravel.com/docs/11.x/eloquent#generating-model-classes)model can be cast to an instance of the South African ID value object (`\Spoorsny\ValueObjects\SouthAfricanId` provided by Composer package [`spoorsny/south-african-id`](https://packagist.org/packages/spoorsny/south-african-id)).

```
use Spoorsny\Laravel\Casts\AsSouthAfricanId;

/**
 * Get the attributes that should be cast.
 *
 * @return array
 */
protected function casts(): array
{
    return [
        'south_african_id' => AsSouthAfricanId::class,
    ];
}
```

Contributing
------------

[](#contributing)

To contribute to the package, see the [Contributing Guide](CONTRIBUTING.md).

License
-------

[](#license)

Copyright © 2024 Geoffrey Bernardo van Wyk

This file is part of package spoorsny/laravel-south-african-id.

Package spoorsny/laravel-south-african-id is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Package spoorsny/laravel-south-african-id is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with package spoorsny/laravel-south-african-id. If not, see .

For a copy of the license, see the [LICENSE](LICENSE) file in this repository.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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

Every ~1 days

Total

3

Last Release

643d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f655900aa4d2538ee47a2c32177238d5d8c9bd2847fc91e7b08d26315f27a3f?d=identicon)[geoffreyvanwyk](/maintainers/geoffreyvanwyk)

---

Top Contributors

[![geoffreyvanwyk](https://avatars.githubusercontent.com/u/194185?v=4)](https://github.com/geoffreyvanwyk "geoffreyvanwyk (18 commits)")

---

Tags

casteloquent-modelsidentity-numberlaravellaravel-packagepackagesouth-africavalidationvalidation-rulesvalue-objectlaravelvalidationpackageeloquentcastattributeSouth Africavalidation ruleID numberidentity numberspoorsny

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spoorsny-laravel-south-african-id/health.svg)

```
[![Health](https://phpackages.com/badges/spoorsny-laravel-south-african-id/health.svg)](https://phpackages.com/packages/spoorsny-laravel-south-african-id)
```

###  Alternatives

[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[esensi/model

The base model traits of Esensi

20266.5k1](/packages/esensi-model)[henzeb/enumhancer

Your framework-agnostic Swiss Army knife for PHP 8.1+ native enums

69287.4k2](/packages/henzeb-enumhancer)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[digitalcloud/laravel-blameable

Laravel package allow you to add created/updated by attributes on eloquent models

1543.3k4](/packages/digitalcloud-laravel-blameable)

PHPackages © 2026

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