Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: (How) is it possible to link to a named route with a parameter?

I have defined the following route:

Route::get('/tours/{country_identifier}', ['as' => 'country', 'uses' => 'CountryController@index']);

Now I would like to link to this named route using something like

route('country')

with a parameter for {country_identifier} filled in, e.g. '/tours/Canada'.

How can I make this happen?

like image 258
Pim Avatar asked Dec 25 '22 18:12

Pim


2 Answers

You can pass the parameters as second argument array:

route('country', ['country_identifier' => $someValue]);

You can take a look at the documentation, there are a lot of useful examples there :)

like image 160
Sh1d0w Avatar answered Dec 28 '22 06:12

Sh1d0w


To link from a view use (assuming you use blade)

<a href="{{ URL::route('country', array('country_identifier' => $var)) }}">$var</a>
like image 43
Szenis Avatar answered Dec 28 '22 08:12

Szenis