Support the ongoing development of Laravel.io →
Forms Validation

We have a checkout where customers can either create an account or checkout as a guest. If they register then the email and password columns in the database are both filled, whereas going as a guest only populates the email column and the password is left blank.

If a user tries to register a full account we need to make sure the e-mail address isn't already in use BY ANOTHER ACCOUNT - similarly, guest users need to be able to reuse the same address multiple times. So just using "unique:table,email" isn't quite enough - if registering, we also need to make sure the password has been populated.

How can I extend L5.1 validation to allow this? I've looked at the additional where clause section here: http://laravel.com/docs/5.1/validation#rule-unique but it looks like it has to be an equals clause. Is there a way to do "email is unique AND password is NOT empty"?

Last updated 2 years ago.
0

Taken an alternative approach and have created a 'guest' column in the database which I'm checking instead. This has solved my problem although I would welcome any replies pointing out whether my original plan is actually doable.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

MikkyX mikkyx Joined 10 May 2015

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.