首页 > 解决方案 > 使用 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');

标签: laravelionic3

解决方案


你确定使用 PUT 请求吗?因为需要 CSRF 令牌请检查

https://stackoverflow.com/questions/30756682/laravel-x-csrf-token-mismatch-with-postman

推荐阅读