Support the ongoing development of Laravel.io →
posted 10 years ago
Security

this is code in route



Route::post('form-submit', function(){
 //get all inputs
 $inputs = Input::all();
 //create array of validation rules
 $rules = array('username'=>'required|foo|min:4|max:35','email'=>'required|email');
 //set custom error messages
 $messages = array(
     'foo'=>'Field value must be foo'
 );
 //validate inputs
 $validator = Validator::make($inputs,$rules,$messages);
 if($validator->passes()){
  //inputs valid
  echo 'Well';
 }else{
  //return to form view with errors
  return Redirect::to('form')->withErrors($validator);
 }
});


but my main question is where the file is extended ... where will this code file where the function is declared "foo"


Validator::extend('foo', function($field,$value,$parameters){
 //return true if field value is foo
 return $value == 'foo';
});
Route::get('form', function(){
 //render app/views/form.blade.php
 return View::make('form');
});

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

juanbon juanbon Joined 1 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.