Laravel通过路线中的数组 [英] Laravel pass array in route
本文介绍了Laravel通过路线中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有代码:
{{ route('data', ['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123]) }}
在路线上:
Route::get('/data/{array?}', 'ExtController@get')->name('data');
在ExtController中:
In ExtController:
class GanttController extends Controller
{
public function get($array = [],
Request $request){
$min = $array['min'];
$max= $array['max'];
$week = $array['week'];
$month = $array['month'];
}
但是这不起作用,我无法在数组中获取参数.如何在控制器中获取参数?
But this is not working, I not get params in array. How I can get params in controller?
我尝试使用以下功能: serialize
,但出现错误:缺少该路线的必需参数.
因为我在路线中有?
I tryeid do with function: serialize
, but I get error: missing required params of the route.
Becuase I have ?
in route.
推荐答案
就像您一样:
{{ route('data', ['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123]) }}
路线:
Route::get('/data', 'ExtController@get')->name('data');
控制器:
class GanttController extends Controller
{
public function get(Request $request){
$min = $request->get('min');
$max= $request->get('max');
$week = $request->get('week');
$month = $request->get('month');
}
}
您的数据将作为 $ _ GET
参数传递-/data?min = 12& max = 123& week = 1& month = 123
Your data will be passed as $_GET
parameters - /data?min=12&max=123&week=1&month=123
这篇关于Laravel通过路线中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文