在Laravel中保存动态表单中的数据

时间:2017-03-02 06:46:14

标签: php forms laravel dynamicform

我一直在尝试在Laravel 5.3中保存动态表单中的数据。但我无法将其保存为数组。错误显示

  

传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须是数组类型,给定字符串......

形式:

protected $fillable = ['client_id', 'amount'];

public function client()
{
    return $this->belongsTo('App\Client');
}

型号:

public function store(Request $request)
{
    $count = Client::count();

    $payment = Payment::create(['amount' => $request->amount,
                                 'client_id'  => $request->client_id,
                                 ]);
    $payment->save();

    return redirect()->action('PaymentController@index');
}

控制器:

int main()
{   
    X509 *x509,*x509ser;    
    BIO *certBio = BIO_new(BIO_s_file());   
    char * path = "E:\\share\TempCert.pem"; // certificate path
    int len;
    unsigned char *buf;
    buf = NULL;

    BIO_read_filename(certBio, path); // reading certificate to bio
    x509 = PEM_read_bio_X509_AUX(certBio, NULL, 0, NULL);  //converting to x509  
    len = i2d_X509(x509, &buf);  // converting to unsigned char*
    x509ser = d2i_X509(NULL, &buf, len); // converting back to x509 from unsigned char*

    BIO_free_all(certBio); 
    return 0;
} 

请帮助解决这个问题。谢谢。

2 个答案:

答案 0 :(得分:4)

  

您正在提交包含文本字段数组的表单并选择框,请尝试   以下

public function store(Request $request)
{
    $count = Client::count();
    foreach( $request->client_id as $key=>$val){
    $payment = Payment::create(['amount' => $request->amount[$key],
                                 'client_id'  => $val,
                                 ]);
 }

 return redirect()->action('PaymentController@index');
}

答案 1 :(得分:0)

Ty创建这样的记录:

$payment = Payment::create($request->input);

并将您的重定向操作更改为:

View::make('path/to/view/')

或仅使用back();来测试它是否有效