php - Laravel Controller request array empty for Route with Parameters
问题描述
I want to have an SEO friendly url's for this I made a jquery function where I visit the web page. like mentioned in blade.php.
The parameters are successfully passed in the url but I am not receiving it on controller side. and display empty or null .
index.blade.php
var v_href = "http://mywebsite.com/program/course/"+discipline+"/"+city+"/"+discipline_id+"/"+city_id;
v_href = v_href.replace('--', '-');
window.location.href = v_href;
Route file
web.php
Route::get('/program/course/{discipline?}/{city?}/{discipline_id?}/{city_id?}', 'FinderController@index')->name('finder.index');
Controller function
$discipline_id = $request->input('discipline_id');
$city_id = $request->input('city_id');
but I am getting null in both variables
解决方案
要检索路由参数,您必须将它们作为参数添加到控制器函数。所以,在你的情况下,说函数被调用getSource()
,你可以这样做:
public function getSource(?string $discipline = null, ?string $city = null, ?int $discipline_id = null, ?int $city_id = null)
{
dd($discipline, $city, $discipline_id, $city_id);
}
推荐阅读
- python - Python彩票生成器我试图弄清楚如何添加一个数字输入,并将它们分开并成为x数量的num long
- angular - Ag-grid + Angular 2:动态更改行节点中列的cellClass
- runtime - 运行时间和 theta 符号
- go - 为什么命令“go clean -n -r -i github.com/ethereum/go-ethereum...”不起作用?
- android - 混淆 API 是什么意思?
- c# - 自定义 ListViewItem 控件显示类名,其中常规 ListView 控件显示实际数据
- react-native - React-Native Redux Navigation 返回第一页 问题
- php - 在潜在客户模块中导出关系字段
- amazon-web-services - Ruby 捆绑控制台未从 ~/.aws/credentials 加载 aws 共享凭证
- c++ - 在立方体内画金字塔