Laravel 4 - how to use a unique validation rule / unique columns with soft deletes?

前端 未结 5 1308
盖世英雄少女心
盖世英雄少女心 2020-12-29 11:24

Assume, you are trying to create a new user, with a User model ( using soft deletes ) having a unique rule for it\'s email address, but there exists a trashed user within th

5条回答
  •  無奈伤痛
    2020-12-29 12:12

    Your Eloquent model should have the $softDeletes property set. If so, then when you perform a WHERE check, like User::where('username', 'jimbob'), Eloquent will automatically add in the query WHERE deleted_at IS NULL... which excludes soft deleted items.

提交回复
热议问题