Php 为什么laravel delete()函数出现错误?
我的表没有主键。我想同时使用userId和cartIdPhp 为什么laravel delete()函数出现错误?,php,laravel,primary-key,primary-key-design,Php,Laravel,Primary Key,Primary Key Design,我的表没有主键。我想同时使用userId和cartId public function delete($uyeid,$Id){ $this->getCart($Id)->delete(); } public function getCart($Id){ try { $data = getCart::whereCartId($Id)->get(); return $data; } catch(\Exception $e
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()
在getUserCart()函数中更改此行:
$data = getUserCart::whereCartId($cartId)->firstOrFail();
进入
错误出现在where子句中。因此,请更改它,我希望它会有所帮助。您的模型看起来怎么样?您的数据库结构是什么样子的?
whereCartId
来自何处?您在查询中获得$cartId并使用$vartId。请将其更改为$this->repo->getUserCart($cartId)->delete()@ChristopherDosin whereCartId它只是来自模型我用ide制作的_helper@ManojPatel我编辑了我的问题,我认为您需要在查询中定义列名及其值,如$this->repo->getUserCart('id',$cartId)->delete();
$data = getUserCart::whereCartId($cartId)->firstOrFail();
$data = getUserCart::find($cartId);
//OR
$data = getUserCart::where('CartId',$cartId)->firstOrFail();