PHP code example of laracasts / validation

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

    

laracasts / validation example snippets


'Laracasts\Validation\ValidationServiceProvider'

 namespace MyApp\Forms;

use Laracasts\Validation\FormValidator;

class Login extends FormValidator {

	/**
	 * Validation rules for logging in
	 *
	 * @var array
	 */
	protected $rules = [
		'username' => '

use MyApp\Forms\Login as LoginForm;
use Laracasts\Validation\FormValidationException;

// ...

protected $loginForm;

public function __construct(LoginForm $loginForm)
{
    $this->loginForm = $loginForm;
}

public function store()
{
    $input = Input::all();

    try
    {
        $this->loginForm->validate($input);

        // login user, do whatever, redirect
    }
    catch (FormValidationException $e)
    {
        return Redirect::back()->withInput()->withErrors($e->getErrors());
    }

}

 namespace MyApp\Forms;

use Laracasts\Validation\FormValidator;

class Registration extends FormValidator {

	/**
	 * Validation rules for registering
	 *
	 * @var array
	 */
	protected $rules = [
		'username' => '

$this->registrationForm->validate(Input::all());