如何在laravel 5.2中更新现有客户?

时间:2016-11-29 05:02:38

标签: laravel-5.2

当我运行此代码时,会在表中插入一个新行。我想要连续更新现有客户。

public function savepayment(Request $request,$amount)
{
    $title ='Save Payment';
    $payment = new Customer();
    $payment ->paid = 'yes';
    $payment->save();

    Session::flash('flash_notification', array('level' => 'success', 'message' => 'Amount Paid Successfully'));

    return Redirect::action('Admin\CustomerController@paymentcustomer');
}

1 个答案:

答案 0 :(得分:0)

试试这个

public function savepayment(Request $request,$amount)
{
    $title ='Save Payment';
    $payment = Customer::find('customer_id'); //need to find the customer before updating the existing customer
    $payment ->paid = 'yes';
    $payment->update(); //use update() instead of save()

    Session::flash('flash_notification', array('level' => 'success', 'message' => 'Amount Paid Successfully'));

    return Redirect::action('Admin\CustomerController@paymentcustomer');
}