2017 © Pedro Peláez
 

library validator

A Form Validation Class for Laravel 4

image

srlabs/validator

A Form Validation Class for Laravel 4

  • Tuesday, March 1, 2016
  • by SRLabs
  • Repository
  • 1 Watchers
  • 1 Stars
  • 234 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

Laravel Form Validator - Deprecated

No Maintenance Intended, (*1)

Inspired by Laracasts' Form Validator this package provides an easy method for validating form data, including checks for unique values., (*2)

This package is no longer being maintained., (*3)

Installation

This package should be installed via composer:, (*4)

$ composer require srlabs/validator

Usage

To use the form validator, first create a form class that extends SRLabs\Validator\Validation\FormValidator. This class will specify the rules and custom messages you want to use when validating this form. For example:, (*5)

<?php namespace Epiphyte\Forms;

use SRLabs\Validator\Validation\FormValidator;

class UpdateProductionForm extends FormValidator {

    protected $rules = array(
        'name' => 'required|alpha|unique:productions',
        'author' => 'required'
    );

    protected $messages = array(
        'name.unique' => 'There is already a production with that name.'
    );
}

Next, inject your custom form class into the controller handling your form submission., (*6)

<?php

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;
    }

    // ...
}

To validate form data, do this in your controller method:, (*7)

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');
}

Note that if the validation fails, an exception will be thrown (and subsequently caught) forcing a redirect back to the form, sending along the error messages and old input as well., (*8)

To validate a field containing a unique rule, pass the corresponding object to the form class:, (*9)

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');
}

Roadmap

  • The tests need to be flushed out and greatly improved.
  • Eventually I will add some config options.

The Versions

01/03 2016

dev-master

9999999-dev http://stagerightlabs.com/projects/laravel-form-validator

A Form Validation Class for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ryan C. Durham

laravel validation

01/03 2016

v1.0.2

1.0.2.0 http://stagerightlabs.com/projects/laravel-form-validator

A Form Validation Class for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ryan C. Durham

laravel validation

16/02 2016

v1.0.1

1.0.1.0 http://stagerightlabs.com/projects/laravel-form-validator

A Form Validation Class for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ryan C. Durham

laravel validation

06/09 2014

v1.0.0

1.0.0.0

A Form Validation Class for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ryan C. Durham

laravel validation