I am trying to have my own simple custom validation function
Here is my code :
$rules = array(
'first_name'=>'required|alpha|min:2',
'last_name'=>'required|alpha|min:2',
'email'=>'sometimes',
'password'=>'alpha_num|between:6,12|confirmed',
'password_confirmation'=>'alpha_num|between:6,12'
);
// run the validation rules on the inputs from the form
$input = Input::all();
$validator = Validator::make($input, $rules );
$validator->sometimes('email', 'required|email', function($input)
{
// get user info from db
$user = User::find(Input::get('id'));
if (Input::get('email') != $user->email)
{
// find that email in the database
$foundemail = DB::table('users')->where('email', '=' ,Input::get('email'))->get();
if(!empty($foundemail))
return false;
}
else
{
return true;
}
});
how do I add a custom message to this , basically I need to check for email field: 1). required 2). email 3). if email edited is the same as the one if the database , then continue with the edit. if email is different I need to check inputed email if it is in the database and show an error
how could I do that please help
Thanks