2016-12-29 141 views
0

請幫我,我想插入一個表,其第一行是固定的 ,其他的是由jQuery添加的。在數據庫中插入一個數組laravel 4.2

我的表位於表單的中心。

我的問題是在foreach的水平,我想用我的價值註冊我的分貝我認爲我的錯誤是,我不知道如何在控制器中使用foreach

我的觀點:

<table class="mws-table" id="tableFeesCompSheet"> 
    <thead> 
    <tr> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Max_interval_amount')}}</th> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Law5_fixed_amount')}}</th> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Law5_rate')}}</th> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Law5_min_amount')}}</th> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Law5_max_amount')}}</th> 
     <th>{{Lang::get('labels.fees_comp_sheet_labels.Law5_grace_amount')}}</th> 
     <th class="nosort">{{Lang::get('labels.action')}}</th> 
    </tr> 
    </thead> 
    <tbody> 

    <tr id="myTableRow"> 
     <td> 
     <input type="text" name="max_interval_amount[]" class="amount no-padding" value="{{Input::get('max_interval_amount')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <input type="text" id="law5_fixed_amount" name="law5_fixed_amount[]" class="amount no-padding" value="{{Input::get('law5_fixed_amount')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <input type="text" id="law5_rate" name="law5_rate[]" class="amount no-padding" value="{{Input::get('law5_rate')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <input type="text" id="law5_min_amount" name="law5_min_amount[]" class="amount no-padding" value="{{Input::get('law5_min_amount')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <input type="text" id="law5_max_amount" name="law5_max_amount[]" class="amount no-padding" value="{{Input::get('law5_max_amount')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <input type="text" id="law5_grace_amount" name="law5_grace_amount[]" class="amount no-padding" value="{{Input::get('law5_grace_amount')}}" required="" data-parsley-type="number"> 
     </td> 
     <td> 
     <div rel="tooltip" data-placement="bottom" id="add" class="btn" data-original-title="Ajouter une ligne"> 
      <i class="icon-edit"></i> 
     </div> 
     </td> 
    </tr> 

    </tbody> 
</table> 

jQuery代碼在數組中添加一個新行:

function deleteRecord(ele) { 
    $(ele.parentNode.parentNode).remove(); 
} 
$("#delete").click(function deleteRow() { 
    // console.log('walid'); 
    // $("tr:has(input:checked)").remove(); 
}); 

$('#send').click(function(){ 
    $.each($('.field'), function() { 
     $('<input />').attr('type', 'hidden') 
      .attr('name', $(this).attr('name')) 
      .attr('value', $(this).val()) 
      .appendTo('#add_fees_rules'); 
    } 
); 

$("#add_fees_rules").submit(); 
return false; 
}); 

和我的控制器:

$fees_rules_comp_sheet= input::all(); 

foreach ($fees_rules_comp_sheet as $fees_comp_sheet) { 

    $fees_comp_sheet = new FeesCompSheet(); 
    $fees_comp_sheet->fees_comp_sheet_id = $this->getFeesCompSheetId(); 
    $fees_comp_sheet->max_interval_amount = Input::get('max_interval_amount'); 
    $fees_comp_sheet->law5_fixed_amount = Input::get('law5_fixed_amount'); 
    $fees_comp_sheet->law5_rate = Input::get('law5_rate'); 
    $fees_comp_sheet->law5_min_amount = Input::get('law5_min_amount'); 
    $fees_comp_sheet->law5_max_amount = Input::get('law5_max_amount'); 
    $fees_comp_sheet->law5_grace_amount = Input::get('law5_grace_amount'); 
    $fees_comp_sheet->save(); 
+0

你的錯誤是什麼? –

回答

0

可能有一些潛在的問題根據您提供的信息。我不能確切地說。因爲你沒有提供詳細的錯誤信息。

首先,請檢查您的型號FeesCompSheet文件。如果您沒有以下代碼行,則可能發生錯誤MassAssignmentException

protected $fillable = ['fees_comp_sheet_id','max_interval_amount', 
         'law5_fixed_amount','law5_rate','law5_min_amount', 
         'law5_max_amount','law5_grace_amount']; 

二,請從所有輸入型除去[]name屬性。

e.g

<input type="text" id="law5_rate" name="law5_rate" class="amount no-padding" value="{{Input::get('law5_rate')}}" required="" data-parsley-type="number"> 

,如果我錯了糾正我。 Input::get('law5_rate');含義,name屬性來自您的輸入類型。不是id屬性。

+0

是的,這是我輸入的名稱屬性,我的錯誤是: ErrorException(E_WARNING) HELP preg_replace():參數不匹配,模式是字符串,而替換是數組 – kawtar