Laravel 验证:这些字段的上一个字段的值必须与当前字段的值不同

Laravel 验证:这些字段的上一个字段的值必须与当前字段的值不同,laravel,validation,laravel-5.3,Laravel,Validation,Laravel 5.3,我有一个包含多个文本输入的表单,我想检查这些字段中是否至少有一个在处理到控制器之前从当前值更改 我的表格: {!! Form::open(['url' => 'url']) !!} echo Form::text('street_name',$stree_name); echo Form::text('state',$state); echo Form::text('building_number',$building_number); echo Form::tex

我有一个包含多个文本输入的表单,我想检查这些字段中是否至少有一个在处理到控制器之前从当前值更改

我的表格:

{!! Form::open(['url' => 'url']) !!}
   echo Form::text('street_name',$stree_name);
   echo Form::text('state',$state);
   echo Form::text('building_number',$building_number);
   echo Form::text('postal_code',$postal_code);
{!! Form::close() !!}
我的请求:

 public function rules()
    {

        return [
            FLD_PROFILES_CITY                       => 'max:50',
            FLD_PROFILES_STREET_NAME                => 'max:150',
            FLD_PROFILES_BUILDING_NUMBER            => 'max:50',
            FLD_PROFILES_POSTAL_CODE                => 'max:10',
        ];
    }

在更新控制器方法中:

$current_stored_item = Address::find($address_id); //you have to send $address_id using a hidden field

//fill the item with the "new" data

$current_stored_item->street_name = $request->street_name;

//do it with all fields

if (empty(array_diff_assoc($current_stored_item ->getOriginal()->forgetKey('updated_at'),$current_stored_item ->getAttributes()->forgetKey('updated_at'))){
   //there are no changes!
}else{
  //there are changes!
}

在更新控制器方法中:

$current_stored_item = Address::find($address_id); //you have to send $address_id using a hidden field

//fill the item with the "new" data

$current_stored_item->street_name = $request->street_name;

//do it with all fields

if (empty(array_diff_assoc($current_stored_item ->getOriginal()->forgetKey('updated_at'),$current_stored_item ->getAttributes()->forgetKey('updated_at'))){
   //there are no changes!
}else{
  //there are changes!
}

那么,您在哪里进行检查?从当前值更改是什么意思?您的意思是在文本输入中有默认值???这不好。最佳实践是让表单输入为空并检查无效输入。如果您想在文本输入中显示某些内容,可以使用
占位符
。@而且我已经更新了我的question@Moher不,不是这样的,我正在显示用户输入的值(编辑表单)好的,那么您的验证规则显示您有一个我假设的最大长度?您在哪里尝试确定输入字段中的差异?那么您在哪里进行检查?从当前值更改是什么意思?您的意思是在文本输入中有默认值???这不好。最佳实践是让表单输入为空并检查无效输入。如果您想在文本输入中显示某些内容,可以使用
占位符
。@而且我已经更新了我的question@Moher不,不是这样的,我正在显示用户输入的值(编辑表单)好的,那么您的验证规则显示您有一个我假设的最大长度?您在哪里尝试确定输入字段中的差异?