PHPackages                             morrislaptop/laravel-instantiate-rule - 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. morrislaptop/laravel-instantiate-rule

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

morrislaptop/laravel-instantiate-rule
=====================================

Validate against an object's constructor

v0.1.0(3y ago)33[4 PRs](https://github.com/morrislaptop/laravel-instantiate-rule/pulls)MITPHPPHP ^8.1

Since Aug 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/morrislaptop/laravel-instantiate-rule)[ Packagist](https://packagist.org/packages/morrislaptop/laravel-instantiate-rule)[ Docs](https://github.com/morrislaptop/laravel-instantiate-rule)[ RSS](/packages/morrislaptop-laravel-instantiate-rule/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (6)Used By (0)

[![](https://camo.githubusercontent.com/2bedf63f24cda7efab02da955dc11fb7ef8a060e2f26b73c33a7aac84529b8a3/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31)](https://supportukrainenow.org)

Validate against an object's constructor
========================================

[](#validate-against-an-objects-constructor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/aee3fbe71e6761877bd177c5716025adb012122087f730ab59ac21212b5fa7fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f727269736c6170746f702f6c61726176656c2d696e7374616e74696174652d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morrislaptop/laravel-instantiate-rule)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6d584d11ef94940fda35b5ae685f501160f8f3d471ea360447d98d1b9b0cfe98/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6f727269736c6170746f702f6c61726176656c2d696e7374616e74696174652d72756c652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/morrislaptop/laravel-instantiate-rule/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d230594384736c91c690db72fee83195ce78319568323b80b8da16598a88e360/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6f727269736c6170746f702f6c61726176656c2d696e7374616e74696174652d72756c652f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/morrislaptop/laravel-instantiate-rule/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1984a8497c9f93366a9d43765c2bcdd40326ec663e6a7b34a18f6a04e71525f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f727269736c6170746f702f6c61726176656c2d696e7374616e74696174652d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morrislaptop/laravel-instantiate-rule)

Your validation rules often belong in your domain model. Use the `InstantiateRule` to bring those rules into your Laravel validation.

```
class FormRequest
{
    public function rules()
    {
        return [
            'email' => ['required', new InstantiateRule(EmailAddress::class)]
        ];
    }
}
```

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

[](#installation)

You can install the package via composer:

```
composer require morrislaptop/laravel-instantiate-rule
```

Usage
-----

[](#usage)

As a simple rule

```
class FormRequest
{
    public function rules()
    {
        return [
            'email' => ['required', new InstantiateRule(EmailAddress::class)]
        ];
    }
}
```

For complex objects, it's assumed array keys match the constructor object or are in the order of the constructor.

```
class Address
{
    public function __construct(
        private string $line1,
        private string $postcode,
        private string $country) {
    }
}

$this->jsonPost('/users', ['address' => [
    'line1' => '123 Fake St',
    'postcode' => '90210',
    'country' => 'Australia',
]]);

class FormRequest
{
    public function rules()
    {
        return [
            'address' => ['required', new InstantiateRule(Address::class)]
        ];
    }
}
```

Or you can specify a custom static contructor if you like...

```
class FormRequest
{
    public function rules()
    {
        return [
            'address' => ['required', new InstantiateRule(Address::class, 'createForValidation')]
        ];
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/morrislaptop/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Craig Morris](https://github.com/morrislaptop)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

1381d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ecf933ed5c8b3e08c1880734166cb32d9e66eb50b01bb91ff74018c3e4b61058?d=identicon)[morrislaptop](/maintainers/morrislaptop)

---

Top Contributors

[![morrislaptop](https://avatars.githubusercontent.com/u/67807?v=4)](https://github.com/morrislaptop "morrislaptop (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

---

Tags

laravelmorrislaptoplaravel-instantiate-rule

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/morrislaptop-laravel-instantiate-rule/health.svg)

```
[![Health](https://phpackages.com/badges/morrislaptop-laravel-instantiate-rule/health.svg)](https://phpackages.com/packages/morrislaptop-laravel-instantiate-rule)
```

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ziming/laravel-zxcvbn

Zxcvbn Password validation rule for Laravel

3056.7k](/packages/ziming-laravel-zxcvbn)[laravel-validation-rules/phone

Validate that a phone number is in the correct format

69355.5k](/packages/laravel-validation-rules-phone)[basillangevin/laravel-data-json-schemas

Transforms Spatie Data objects into JSON Schemas with built-in validation

1312.2k1](/packages/basillangevin-laravel-data-json-schemas)

PHPackages © 2026

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