Skip to content
Advertisement

Laravel, only first element of array passed to route is readable

From a blade template I want to pass an array with a variable amount of values to a route, as described in the answer here.

However when I do this I can only ever access the first value in the array I pass to the route.

This is how I call the route in the blade template:

{{ route('stats.downloads', ['stat_kind' => 'files_size', 'group_by' => 'week', 'start' => '2020-11-01', 'end' => '2020-11-10']) }}

this is my route from web.php:

Route::get('stats/downloads', 'StatsController@view_stats_downloads')->name('stats.downloads');

and my controller:

public function view_stats_downloads(Request $request){
    // get the input parameters
    $group_by = $request->get('group_by');
    $stat_kind = $request->get('stat_kind');
    $company = $request->get('group_by');
    $user = $request->get('user');
    $start = $request->get('start');
    $end = $request->get('end');
    
    ...

The problem is, that I can only ever access the first value of the array I pass to the controller (stat_kind in this case). It doesn’t natter in which order I call the get() function either.

What can I do to fix this?

I’m running laravel 5

Advertisement

Answer

Try changing the curly braces, {{ }}, to {!! !!} where you are calling the route helper.

The & is being encoded to & so only the first query string parameter that you are sending does not have a & in front of it so it is named correctly. The others are named with the amp;, the part after the & in the encoded ampersand.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement