簡體   English   中英

為什么 laravel delete() 函數出錯?

[英]Why laravel delete() function getting error?

我的表沒有主鍵。我想一起使用userIdcartId

public function delete($uyeid,$Id){

    $this->getCart($Id)->delete();
}

 public function getCart($Id){
    try {
       $data = getCart::whereCartId($Id)->get();

        return $data;
    } catch(\Exception $e){
        return null;
    }
}

我應該將 2 列定義為主要嗎? 如何?

請更新您的deleteNote()

public function deleteNote($uyeid,$cartId){

    $this->repo->getUserCart($cartId)->delete();
}

getUserCart()函數中更改此行:

$data = getUserCart::whereCartId($cartId)->firstOrFail();

進入

$data = getUserCart::find($cartId);

//OR

$data = getUserCart::where('CartId',$cartId)->firstOrFail();

錯誤發生在where子句中。 所以改變它,我希望它會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM