【发布时间】:2021-02-14 18:15:01
【问题描述】:
我制作 laravel API,我可以在其中存储一个新数据,其中的值是 body raw json 中的值。但是当我尝试使用 post 发送请求时,除了状态为 200 OK,我什么也没得到。当我检查我的 mysql 时,没有输入数据。 那么,我该怎么办?
mysql 数据
Laravel 控制器和 API,
// function in controller
use App\Models\ChartAge;
class ChartController extends Controller
{
public function saveChart(Request $request)
{
$data = $request->validate([
'entity' => 'required|string|max:10',
'code' => 'required|string|max:10',
'year' => 'required|int|max:10',
'under_age_15' => 'required|string|max:50',
'age_15_64' => 'required|string|max:50',
'age_65_over' => 'required|string|max:50',
]);
$values = ChartAge::create($request);
return response()->json(
[
'status' => true,
'message' => "the videos has been favorites",
'data' => $values,
],
201
);
}
}
//in api.php
Route::post("charts", [ChartController::class, 'saveChart']);
这是我尝试使用邮递员发送请求的时候。
因为没有报错,不知道怎么回事??
【问题讨论】: