我已经应用了 Laravel 代码并测试了 API 来删除数据,它成功了。
现在我想将函数 delete 应用于 ionic。如何将其应用于警报功能?
.ts 文件
confirmdelete() {
let alert = this.alertCtrl.create({
title: 'Confirm Delete',
message: 'Do you confirm to delete?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
console.log('Yes clicked');
}
}
]
});
alert.present();
}
所以我在离子中进行删除时遇到问题。我认为我需要在 yes 处理程序中包含什么或什么?我仍然不确定。
api.php
public function deleteMed(Request $request)
{
$id = $request->id;
$medname = $request->medname;
$price = $request->price;
$stock = $request->stock;
$medno = $request->medno;
$ingredient = $request->ingredient;
$description = $request->description;
$addinfo = $request->addinfo;
$user = AddMedicine::where('medno', $request->input('medno'))->count();
if($user!=0) {
AddMedicine::where('id', $id)->delete([
'id' =>$id,
'medname'=>$medname,
'price'=>$price,
'stock'=>$stock,
'medno'=>$medno,
'ingredient'=>$ingredient,
'description'=>$description,
'addinfo'=>$addinfo,
]);
$msg = "Data deleted";
$datamsg = response()->json([
'success' => $msg
]);
return $datamsg->content();
} else {
echo'{"error":{"text":" Medicine does not exist"}}';
}
}