PHP code example of grandadevans / laravel-form-validator

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

    

grandadevans / laravel-form-validator example snippets


/*
 * app/config/app.php
 */
'providers' => array(
    #########
    'Grandadevans\GenerateForm\ServiceProvider\GenerateFormServiceProvider'
);

/*
 * composer.json
 */
"autoload": {
	"classmap": [
		"app/commands",
		"app/controllers",
		"app/models",
		"app/database/migrations",
		"app/database/seeds",
        
        "app/Forms"
    ]
}

protected $loginForm;

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

$this->loginForm->validate(Input::only(['username','password']));




use Laracasts\Validation;

/**
 *
 * Class LoginForm
 *
 */
class LoginForm extends FormValidator {

    /**
     * The array of rules to be processed
     *
     * @var array
     */
    protected $rules=[
        'username' => '

/*
 * app/controllers/LoginController.php
 */
public function LoginController extends BaseController
{

    /**
     * @var LoginForm
     */
    protected $loginForm;
    
    /**
     * @param LoginForm $loginForm
     */
    public function __construct(LoginForm $loginForm)
    {
        $this->loginForm = $loginForm;
    }

    
    /**
     * Validate the login details
     */
    public function validateForm()
    {
        $input = Input::only([
            'username',
            'password'
        ]);
        
        try {
            $this->loginForm->validate($input);
        }
        
        catch(\Laracasts\Validation\FormValidationException $e) {
			return Redirect::back()->withInput()->withErrors($e->getErrors());
	}

        
    // Do something with the data
    
}
bash
composer dump-autoload
bash
php artisan generate:form
bash
php artisan generate:form Login --rules="username|
bash
php artisan generate|form Login --rules="username|