I have a validator that always passes.I need it to fail if username has less than 3 characters.
Here are my routes:
Route::get('/', function()
{
return View::make('validation.form');
});
Route::post('registration', function()
{
// Fetch all request data.
$data = Input::all();
var_dump($data);
// Build the validation constraint set.
$rules = array(
'username' => 'alpha_num|min:3' //or username =>array('alpha_num','min:3')
);
var_dump($rules);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
// Normally we would do something with the data.
return 'Data was saved.';
}
return 'data not saved';
});
And bellow is 'my' form
{{ Form::open(array('url' => 'registration')) }}
{{-- Username field. ------------------------}}
{{ Form::label('username', 'Username') }}
{{ Form::text('username') }}
<br/>
{{-- Email address field. -------------------}}
{{ Form::label('email', 'Email address') }}
{{ Form::email('email') }}
<br/>
{{-- Password field. ------------------------}}
{{ Form::label('password', 'Password') }}
{{ Form::password('password') }}
<br/>
{{-- Password confirmation field. -----------}}
{{ Form::label('password_confirmation', 'Password confirmation') }}
{{ Form::password('password_confirmation') }}
<br/>
{{-- Form submit button. --------------------}}
{{ Form::submit('Register') }}
{{ Form::close() }}
When I click the submit button I am always routed to /registration with the message data saved.Why does the validator not working..?Any idea