0

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.

3
  • Possible duplicate of Need to pass array to route and controller Commented Apr 19, 2018 at 8:41
  • I tried do serialize, I get error: missing required params.. Commented Apr 19, 2018 at 8:42
  • @Jadasdas where does you are getting this error? Commented Apr 19, 2018 at 8:43

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

You write your code in the wrong controller.

Your code must be like:

class ExtController extends Controller
{  

public function get()
{
   // your code
}

}

Comments

0

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');
    }
}

Comments

0

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');

5 Comments

Missing required parameters for [Route: data] [URI: api/data/{array?}] I have: route('data', serialize(['min' => request()->get('min'), 'max' => request()->get('max'), 'week' => request()->get('week'), 'month' => request()->get('month')]))
I do not see any required param, array its optional in that route .
dfauq how can you use request in front end, use javascript to get the data from the form. REQUEST ITS FOR BACKEND
I need pass params on route. I load /data from javascript.
gantt.load("{{ route('data', serialize(['min' => request()->get('min'), 'max' => request()->get('max'), 'week' => request()->get('week'), 'month' => request()->get('month')])) }}");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.