2017-09-13 56 views
0

我有一個包含多個文本輸入的表單,我想檢查這些字段中至少有一個是否從處理前的當前值更改爲控制器。驗證:這些字段必須是一個不同於當前值的值

我的表格:

{!! 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

所以,你在哪裏做檢查? –

+0

你是什麼意思從當前值改變?你的意思是你有文本輸入內的默認值?不是很好。最佳做法是讓表單輸入爲空並檢查無效輸入。如果要在文本輸入內顯示某些內容,可以使用「佔位符」。 – Moher

+0

@AndyHolmes我已經更新了我的問題 – wahdan

回答

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! 
} 
相關問題