简体   繁体   English

为什么 laravel delete() 函数出错?

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

My table does not have a primary key.I want to use userId and cartId together.我的表没有主键。我想一起使用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;
    }
}

Should I define 2 column as primary?我应该将 2 列定义为主要吗? how?如何?

Please update your deleteNote()请更新您的deleteNote()

public function deleteNote($uyeid,$cartId){

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

Change this line in getUserCart() function:getUserCart()函数中更改此行:

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

into进入

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

//OR

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

The error occur in where clause.错误发生在where子句中。 So change it and I hope it would helpful.所以改变它,我希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM