Hello all I have code:
{{ route('data', ['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123]) }}
In routes:
Route::get('/data/{array?}', 'ExtController@get')->name('data');
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?
I tryeid do with function: serialize
, but I get error: missing required params of the route.
Becuase I have ?
in route.
Just do as you did:
{{ route('data', ['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123]) }}
Route:
Route::get('/data', 'ExtController@get')->name('data');
Controller:
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');
}
}
Your data will be passed as $_GET
parameters - /data?min=12&max=123&week=1&month=123
First of you need to serialize the array:
{{ route('data', serialize(['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123])) }}
Then you can pass it :
Route::get('/data/{array?}', 'ExtController@get')->name('data');
You write your code in the wrong controller.
Your code must be like:
class ExtController extends Controller
{
public function get()
{
// your code
}
}
Pass the data as query string parameters.
Define your route as
Route::get('/data', 'ExtController@get')->name('data');
in your view
{{ route('data', ['min' => 12, 'max' => 123, 'week' => 1, 'month' => 123]) }}
and in your controller
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');
}
}