PHP code example of clarkf / simply-valid

1. Go to this page and download the library: Download clarkf/simply-valid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clarkf / simply-valid example snippets




class MyModel extends SimplyValid\Model
{
    protected $rules = array(
        // validation rules here
    );
}

public function store()
{
    $model = new MyModel(Input::get());

    if ($model->save()) {
        // Model is valid, and has been saved!
    } else {
        // Handle validation problems here
    }
}

<div class='field'>
    {{ Form::text('name') }}

    @if ($model->errors()->has('name'))
        <div class='field-error'>
            {{ $model->errors()->first('name') }}
        </div>
    @endif
</div>



class MyModel extends Eloquent
{
    public $rules = array(
        // Validator rules here
    );

    public static function boot()
    {
        parent::boot();
        static::observe(new SimplyValid\ValidityObserver());
    }
}

public static function boot()
{
    parent::boot();
    // ...
    static::registerModelEvent('errors', function (MyModel $model, MessageBag $errors) {
        // Store the errors somewhere useful, for example
        $model->errors = $errors;
    });
}

class User extends SimplyValid\Model
{
    public function getValidationRules()
    {
        $rules = array();

        if (!$this->exists) {
            // User has not yet been created, so a password is