2016-12-29 5 views
0

に配列を挿入してください。助けが必要です。最初の行が固定されているテーブルを挿入したいのですが、 と他はjQueryによって追加されています。データベースlaravel 4.2

私のテーブルはフォームの中央にあります。

私の問題は、私のdbに自分の値を登録するために使用したい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属性から[]を削除してください。私が間違っている場合

例えば

<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

はい、それは私のimputの名前属性、および私が持っているエラーです: ErrorException(E_WARNING) ヘルプ preg_replace():パラメータの不一致、パターンは文字列、置換は配列です – kawtar