Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Validation in Laravel 4.x

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    In any project validation plays an important role.In laravel 4.x we have validation class which is used to validating data and validating error message.

    Basic Validation Example:

    $validator = Validator::make(
        array('name' => 'Dayle'),
        array('name' => 'required|min:5')
    );
    


    Here we can see that make passes as first argument and second argument is validation rules which we want to reply on our data.

    If we want to apply multiple rule on the field then we will use array to implement this.

    $validator = Validator::make(
        array('name' => 'Dayle'),
        array('name' => array('required', 'min:5'))
    )
    


    If we want to updating multiple field then

    $validator = Validator::make(
        array(
            'name' => 'Dayle',
            'password' => 'lamepassword',
            'email' => 'email@example.com'
        ),
        array(
            'name' => 'required',
            'password' => 'required|min:8',
            'email' => 'required|email|unique:users'
        )
    );
    


    When Validator instance is created then by using pass and fail method we will use to validate the data.
    Example:

    if ($validator->fails())
    {
        // The given data did not pass validation
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: