2016-11-29 33 views
0

當我運行這段代碼時,在table中插入了一個新行。我想更新一行中的現有客戶。如何更新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\[email protected]'); 
} 

回答

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\[email protected]'); 
} 
+0

你必須找到客戶更新客戶信息 – Jon