PHPackages                             illuminatech/model-rules - 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. illuminatech/model-rules

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

illuminatech/model-rules
========================

Set of the validation rules to check if a model exists or is unique for Laravel

1.0.4(1mo ago)624BSD-3-ClausePHPCI passing

Since Jun 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/illuminatech/model-rules)[ Packagist](https://packagist.org/packages/illuminatech/model-rules)[ GitHub Sponsors](https://github.com/klimov-paul)[ Patreon](https://www.patreon.com/klimov_paul)[ RSS](/packages/illuminatech-model-rules/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

 [ ![](https://avatars1.githubusercontent.com/u/47185924) ](https://github.com/illuminatech)

Laravel Model Validation Rules
==============================

[](#laravel-model-validation-rules)

This extension provides set of the validation rules to check if a model exists or is unique for Laravel.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/21f9968315b2eeaec7f4c408ff5e2aba70fa5b024c967a302c1f679faab21cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e61746563682f6d6f64656c2d72756c65732e737667)](https://packagist.org/packages/illuminatech/model-rules)[![Total Downloads](https://camo.githubusercontent.com/213bdaf68f086a3289a0c310708c01612f975422388603d1bfcd5b58fdd5ad18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e61746563682f6d6f64656c2d72756c65732e737667)](https://packagist.org/packages/illuminatech/model-rules)[![Build Status](https://github.com/illuminatech/model-rules/workflows/build/badge.svg)](https://github.com/illuminatech/model-rules/actions)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist illuminatech/model-rules

```

or add

```
"illuminatech/model-rules": "*"
```

to the "require" section of your composer.json.

Usage
-----

[](#usage)

This extension provides set of the validation rules to check if a model exists or is unique for Laravel. It serves 2 main purposes:

- define a fluent interface for Eloquent model exist/unique validation,
- remove redundant database queries for Eloquent model manipulations.

Assume we have a database storing some items grouped by categories. While creating an HTTP request handler for the new item saving, we need to check if given category record exists and associate it the new item. There is a well-known recommendation to use relation methods like `associate()` to handle relation instantiation at object level. However, if we follow it along with standard validation, our program performs redundant SQL query. For example:

```
