PHPackages                             filisko/redbean-validation-plugin - 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. filisko/redbean-validation-plugin

ActivePackage

filisko/redbean-validation-plugin
=================================

RedBeanPHP validation plugin for your Models

8484[1 issues](https://github.com/filisko/redbean-validation-plugin/issues)PHP

Since Mar 14Pushed 6y ago3 watchersCompare

[ Source](https://github.com/filisko/redbean-validation-plugin)[ Packagist](https://packagist.org/packages/filisko/redbean-validation-plugin)[ RSS](/packages/filisko-redbean-validation-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RedBean Model Validation Plugin
===============================

[](#redbean-model-validation-plugin)

With this plugin you will be able to filter and validate your RedBean Model, to do that, the plugin itself uses **[GUMP](https://github.com/Wixel/GUMP)**, a standalone PHP data validation and filtering class, which means that this plugin requires it, but do not worry as Composer will handle that dependency.

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

[](#installation)

Install the plugin through composer:

`composer require filisko/redbean-validation-plugin`

Once you installed the plugin with composer, you have to load it into RedBean like this:

```
R::ext('validate', function($bean){
    return Filisko\RedBeanPHP\Plugin\ModelValidation::validate($bean);
});
```

You will probably have something like that after adding the validation plugin;

```
R::setup('mysql:host=localhost;dbname=my_database','root', 'password');
R::freeze(TRUE);
R::ext('validate', function($bean){
    return Filisko\RedBeanPHP\Plugin\ModelValidation::validate($bean);
});
```

How to use
----------

[](#how-to-use)

The thing that matters here is that RedBean must be able to "connect" the bean with this model. The mechanism in RedBeanPHP that connects beans to models is called FUSE, because beans are fused with their models. [Read more about RedBean Models](http://www.redbeanphp.com/index.php?p=/link_beans)

Now, the important thing here is to make sure that your Model **contains the rules**, which will be used by GUMP to do the work.

#### Available options for fields

[](#available-options-for-fields)

**label**: This option is used to replace the field name with the label on errors, and instead of showing the field name, show the label.

**filter**: This option is used to apply any filter to the value of a specific field.

**validation**: This option is used to validate the value of a specific field.

Please have a look to the available validations and filters on [GUMP GitHub repository](https://github.com/Wixel/GUMP).

**message**: This option is used to use a custom error message, remember that you must be very clear as it will show this error for any validation failure.

### Examples

[](#examples)

An example of a RedBean model and his rules. Remember that you can always use your own model, the **MOST IMPORTANT** thing is RedBean to be able to FUSE (connect) your Bean with your Model so the validation plugin can use the specified rules inside your Model using the Bean. It may sound a bit complicated but with the examples below you will see how easy it is.

**User.php**

```
