0

In Laravel, how do I do validation to check if checkbox is checked and text input is not empty.

For example:

If checkbox is ticked

<input type="checkbox" name="has_login" checked="checked" value="1">

and pin is not empty then validation should be passed.

<input type="text" name="pin" value="">

In Request file file:

public function rules()
{
    return [
          'has_login' => ??,
    ];
}
4
  • 1
    what's your checkbox name? Commented Jul 21, 2016 at 16:40
  • laravel.com/docs/5.1/validation#available-validation-rules First one is "accepted" and you can combine it with "pin" => "required" Commented Jul 21, 2016 at 16:41
  • @apokryfos How to combine with "pin" => "required" Commented Jul 21, 2016 at 16:45
  • You should really read the documentation. All the information is there. Commented Jul 22, 2016 at 7:55

1 Answer 1

1

You should try this way:

public function rules()
{
    return [
          'has_login' => 'accepted',
          'pin' => 'required',
    ];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.