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

Posted 2 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.