PHP code example of srlabs / validator

1. Go to this page and download the library: Download srlabs/validator 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/ */

    

srlabs / validator example snippets


 namespace Epiphyte\Forms;

use SRLabs\Validator\Validation\FormValidator;

class UpdateProductionForm extends FormValidator {

    protected $rules = array(
        'name' => '



use Epiphyte\Forms\CreateProductionForm;
use Epiphyte\Forms\UpdateProductionForm;

class ProductionController extends \BaseController {

    protected $createProductionForm;
    protected $updateProductionForm;

    /**
     * @param CreateProductionForm $createProductionForm
     */
    public function __construct(
        CreateProductionForm $createProductionForm,
        UpdateProductionForm $updateProductionForm)
    {
        $this->createProductionForm = $createProductionForm;
        $this->updateProductionForm = $updateProductionForm;
    }

    // ...
}

public function store()
{
    // Gather the Data
    $data = Input::only('name', 'author');

    // Validate the Form
    $this->createProductionForm->validate($data);

    // Create the Production
    Epiphyte\Production::create($data);

    Session::flash('success', 'Production Added');
    return Redirect::action('ProductionController@index');
}

public function update($id)
{
    $production = Epiphyte\Production::find($id);
    $data = Input::only('name', 'author');

    $this->updateProductionForm->validate($data, $production);

    $production->name = $data['name'];
    $production->author = $data['author'];
    $production->save();

    Session::flash('success', 'Production Updated');
    return Redirect::action('ProductionController@index');
}