Download the PHP package illuminatech/model-rules without Composer

On this page you can find all versions of the php package illuminatech/model-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package model-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-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

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

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:

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:

To solve this issue you can use Illuminatech\ModelRules\Exists validation rule. During the validation it "remembers" the last queried model instance, which can be retrieved using getModel() method. For example:

You can use Illuminatech\ModelRules\Unique to setup a validation for unique model attribute. For example:

Customize Database Query

You can pass query builder instance directly to model validation rule. This allows you to specify any custom search conditions or use a relation query. For example:

Note: this extension does not put explicit restriction on the query builder object type - it simply expected to match database query builder notation. Thus, you may create a custom query builder class, which works with special data storage like MongoDB or Redis, and pass its instance as a data source. If its methods signature matches \Illuminate\Database\Query\Builder - it should work. Although it is not guaranteed.

Customize error message

You can setup a custom error message for model rules using withMessage() method. In case a model instance is available after validation failure, its attributes can be used as a placeholders in the error message using syntax: model_{attribute}. For example:

Validate multiple models

Assume we have a database, where items and categories are linked as 'many-to-many'. In such case the request for the item storage will contain a list of category IDs, which should be associated with it. The ordinary request handler for this may look like following:

You can reduce the numbers of database queries for such a scenario using Illuminatech\ModelRules\MultiExist validation rule. For example:

Note: as you may have guessed, there is also Illuminatech\ModelRules\MultiUnique validation rule, however its real-world implications are quite limited.

Heads up! Remember, that model validation rules are not cumulative, each rule remembers only the last queried model. Thus, it will not serve you well during nested array validation, like in case you want to store multiple items as batch per single HTTP request. It is better to separate validation into multiple steps for such cases. For example:

Working with Form Requests

You can use model rules with Form Request Validation. For example:


All versions of model-rules with dependencies

PHP Build Version
Package Version
Requires illuminate/validation Version ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package illuminatech/model-rules contains the following files

Loading the files please wait ....