xxxxxxxxxx
'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id
xxxxxxxxxx
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
Validator::make($data, [
'email' => [
'required',
Rule::unique('users')->ignore($user->id),
],
]);
xxxxxxxxxx
use Illuminate\Support\Facades\Validator;
// Assuming you have a form request class for validation
class UpdateUserRequest extends FormRequest
{
public function rules()
{
$userId = $this->route('user'); // Assuming the route parameter is named 'user'
return [
'email' => [
'required',
'email',
Rule::unique('users')->ignore($userId),
],
// Add more validation rules for other fields if needed
];
}
}
xxxxxxxxxx
$validator = Validator::make($request->all(), [
'email' => 'unique:users,email_address,'.$user->id.',id',
]);
$validator->sometimes('email', 'unique:users', function ($input) use ($user) {
return $input->email != $user->email;
});
if ($validator->fails()) {
// Validation failed
} else {
// Validation successful
}