Api控制器
public function store(Request $request)
{
$statistics = Statistics::create($request->all());
return response()->json($statistics, 201);
}
路线路线:get("统计",[StatisticsController::类,"存储"]);
旋度函数
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/kdk_local/statistics");
curl_setopt($ch, CURLOPT_POSTFIELDS,
"game_id=3&user_id=3&bet=3&win=3&session_id=3");
curl_exec($ch);
curl_close($ch);
请清除路由缓存:
php artisan route:clear
如果不工作,删除此文件:
bootstrap/cache/routes-v7.php
或
bootstrap/cache/routes.php
在路由文件中将get
改为post
:
Route::post('statistics', [StatisticsController::class,'store']);
使用API路由(
api.php
)对外调用API