To ignore soft deleted records during unique validation in Laravel, you can use the ignore validation rule. Here's an example of how you can modify your existing validation rule:
use Illuminate\Validation\Rule;
public function rules()
{
$id = $this->route('id'); // assuming you're using route model binding
return [
'email' => [
'required',
'email',
Rule::unique('users')->ignore($id)->whereNull('deleted_at')
]
];
}
In this example, we're using the ignore rule to exclude the record with the given $id from the unique check. Additionally, we're using the whereNull method to only consider records where the deleted_at column is null (i.e. not soft deleted).
Note that you'll need to adjust the table name and column name in the unique rule to match your specific use case.