How to make an multiple unique index with a special value?

Posted 8 months ago by alihoushyaripour


I have two column for user with name username and is_active that every active user have an unique username and can exist more than one similar username for don't active users, it means that if an user want to activate, must have a unique username for himself.

Because that I need to set an unique index according to mentioned conditions.

I was write it like this but not match with condition2:

$table->unique(['username', 'is_active']);

How can I do it?

Please sign in or create an account to participate in this conversation.