如何从http请求中获取第一个参数

How do I get the first parameter from http request

我正在使用 Laravel 8。用户单击包含 id# (http://wxyz.abc/2) 的 link 我的应用从浏览器接收 $request 并通过 Route::post('/comments', [CommentController::class, 'store']); 将其发送到商店功能 我的问题是如何将 id# 放入 php 变量中?

只需使用一个路由参数:

Route::post('/comments/{id}', [CommentController::class, 'store']);

在你的控制器中:

public function store(Request $request, $id)
{
  echo $id;
}

在此处阅读更多内容:https://laravel.com/docs/requests