我要按如下所示设置参数
例如
http://localhost/firecek_web/pengaduan?barcode=8571385
路线
Route::get('/pengaduan','PengaduanController@index');
答案 0 :(得分:1)
您无需更改路线定义。保持原样:
Route::get('/pengaduan', 'PengaduanController@index');
然后,只需在发出请求时将其附加到您的网址中即可(就像您在描述中所说的那样):
http://localhost/firecek_web/pengaduan?barcode=8571385
^^^^^^^^^^^^^^^^
然后在您的控制器中:
PengaduanController.php
public function index(Request $request)
{
$value = $request->query('barcode');
// this also works:
$value = $request->get('barcode');
// or even this:
$value = $request->barcode;
dd($value); // '8571385'
}
检查文档的this section:
从查询字符串中检索输入
虽然
input
方法从整个请求有效负载中检索值 (包括查询字符串),query
方法将仅检索 查询字符串中的值:$name = $request->query('name');
如果请求的查询字符串值数据不存在,则第二个 该方法的参数将返回:
$name = $request->query('name', 'Helen');
您可以不带任何参数地调用
query
方法,以便 检索所有查询字符串值作为关联数组:$query = $request->query();