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