lundi 31 août 2015

Laravel Database unique key between different fields

I'm building a website in laravel. The user table has two email fields, an 'email' field and a 'new_email' field. When the user wants to change emails, it gets stored in the 'new_email' first, then when the user confirms it updates the 'email' field.

All good, but I want to restrict the 'new_email' field to be unique when comparing to the 'email' field. So that no user could change his email to an existing user. I'll do the check on the php side too, but I want the database to restrict that.. so I tried the following:

    Schema::table('users', function ($table) {
        $table->string('new_email')->unique('email')->nullable();
    });

Didn't work out, I still can add an email to the 'new' field, even when it's alerady on the email..

So, how can I achieve this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NTsPrB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire