Alexander Solonik
Alexander Solonik

Reputation: 10240

Why am i getting a String in laravel method when i am actually passing a array

I have the following line of code in my view file in laravel::

<a href="{{ route('showQualityResult' , ['data' => Session::get('quality-data')]) }}">Submited Quality Check</a>

The following route is setup in my routes file:

Route::get('showQualityResult/{data}', [
    'as' => 'showQualityResult', 
    'uses' => 'QualityCheckController@showQualityResult'
]);

When clicked on the a tag the folling controller emthod is run:

public function showQualityResult($qualityData) {
        return $qualityData;
}

As of now i get the following string in my view:

45

Why am i getting this string/Number ?? When clearly i am passing an array in the route method used as following:

<a href="{{ route('showQualityResult' , ['data' => Session::get('quality-data')]) }}">Submited Quality Check</a>

Can somebody elaborate and explain this to me please as i am a bit suprised as of now with the result that i am getting.

Upvotes: 0

Views: 214

Answers (1)

patricus
patricus

Reputation: 62338

The second parameter to the route() method expects an array of parameters to send to the route. It loops through the array you pass in and replaces route parameters with the values specified in the array.

So, in this case, you've specified there is one parameter, named data, and it has the value of Session::get('quality-data') (which, I'm assuming is 45), so it takes your route definition showQualityResult/{data} and creates the actual route of showQualityResult/45.

Upvotes: 1

Related Questions