简体   繁体   中英

Why laravel delete() function getting error?

My table does not have a primary key.I want to use userId and cartId together.

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? how?

Please update your deleteNote()

public function deleteNote($uyeid,$cartId){

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

Change this line in getUserCart() function:

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

into

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

//OR

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

The error occur in where clause. So change it and I hope it would helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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