php - 如何制作变量“?” 在 laravel 5.8 中
问题描述
我想制作如下参数
例如
http://localhost/firecek_web/pengaduan?barcode=8571385
路线
Route::get('/pengaduan','PengaduanController@index');
解决方案
您无需更改路线定义。保持原样:
Route::get('/pengaduan', 'PengaduanController@index');
然后,在发出请求时将其附加到您的 url(就像您在描述中那样):
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'
}
检查文档的这一部分:
从查询字符串中检索输入
虽然该
input
方法从整个请求负载(包括查询字符串)中检索值,但该query
方法只会从查询字符串中检索值:$name = $request->query('name');
如果请求的查询字符串值数据不存在,则返回此方法的第二个参数:
$name = $request->query('name', 'Helen');
您可以
query
不带任何参数调用该方法,以便将所有查询字符串值作为关联数组检索:$query = $request->query();
推荐阅读
- python - 如何使用 lambda 传递两个参数(参数之一是事件)?
- r - R 组合使用 dplyr 的 pull 创建的多个向量
- google-sheets - 根据团队名称导入“姓名”和“预期回报”列表
- c++ - 自身类中的类变量 C++
- html - 'PREV'按钮不能以多步形式工作 - jQuery
- alexa-skills-kit - 为什么我的话语没有触发意图?
- cordova - 电容器项目中 Cordova 插件的变量名称
- powershell - 如何转义 .ps1 文件中的换行符?
- python - 在多个文本文件中搜索一个字符串并打印该字符串所在的文件名
- angular - 如何在 Angular 中使用自定义管道覆盖默认的“异步”管道?