laravel - 使用 api 将数据更新到数据库 laragon
问题描述
我想将数据更新到离子数据库中。如何进行数据更新。这是我尝试过的。我尝试使用邮递员发布 api,它似乎成功,但数据没有改变。
在 api.php
public function update (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;
AddMedicine:: where('medname',$medname)->update([
'id' =>$id,
'medname'=>$medname,
'price'=>$price,
'stock'=>$stock,
'medno'=>$medno,
'ingredient'=>$ingredient,
'description'=>$description,
'addinfo'=>$addinfo,
]);
$msg = "Data Updated";
$datamsg = response()->json([
'success' => $msg
]);
return $datamsg->content();
}
路线
Route::put('/update','ApiController@update');
解决方案
你确定使用 PUT 请求吗?因为需要 CSRF 令牌请检查
https://stackoverflow.com/questions/30756682/laravel-x-csrf-token-mismatch-with-postman
推荐阅读
- javascript - Firebase Functions 不会更新所需的文件
- c - 根据 C 标准,哪些字符在 C 中的预处理指令之前和之后有效
- android-studio - 无法设置用户 ID,jwt 被拒绝:Forbidden: Invalid JWT issuer
- sql - 使用 SQL 通过索引选择大量行
- asp.net-mvc - 将模型传递给用于模态的局部视图
- database - 转储、下载、快照和备份有什么区别?
- python - 为什么有时使用 findAll 会得到空数组?
- ios - Flutter - Firebase 云消息传递,iOS 上未收到数据消息
- java - 禁用CORS错误时Spring安全默认登录不起作用
- javascript - 如何使不和谐机器人的命令不区分大小写