1
目前的设置:Laravel - 从一个函数传递到另一个数据路由的功能
目前,用户可以搜索调用后的路线。然后它根据搜索返回各种东西到search.results
,它在URL中显示为place/town
。
如何将lat
和lng
变量从search
函数传递到showResults
函数。我试过->with()
,它返回null,并且将它们包含在当前的[$place, $town]
数组中,但它们随后包含在URL中。
路线:
Route::post('search', '[email protected]')->name('search');
Route::get('{place}/{town}', '[email protected]')->name('search.results');
控制器:
搜索功能:
public function search(Request $request)
{
$place =$request->get('name');
$lat = $request->get('lat');
$lng = $request->get('lng');
return redirect()->route('search.results', [$place, $town]);
}
showResults功能(空的时刻):
public function showResults()
{
// I want to use lat and lng here.
}
我非常接近!谢谢。是否有任何理由为什么我的纬度值不会发送 - '“-1.5490773999999874”'这是''dd'('''search'函数内的变量,但它在'showResults' 。经度完美吗? – Ben
你怎么发送你的两个变量? (''lat',$ lat) - >用'('l',$ lng);'' – Roadirsh
多个' - > with()'可以完美地工作。感谢您的帮助! – Ben