我有一个包含多个文本输入的表单,我想检查这些字段中的至少一个是否在处理之前从当前值更改为控制器。
我的表格:
{!! 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() !!}
我的vaidationRequest:
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',
];
}
答案 0 :(得分:2)
在您的更新控制器方法:
$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!
}