4

I'm trying to create a route with an array of aliases, so when I call whois or who_is in the url it goes to the same route.

Then I don't need to keep repeating the code every time, changing only the alias.

I tried the code below.

Variables in the routes:

$path = 'App\Modules\Content\Controllers\ContentController@';
$aliases['whois'] = '(quemsomos|who_is|whois)';

Routes:

Route::get('{whois}', array('as' =>'whois', 'uses' => $path.'getWhois'))->where('whois', $aliases['whois']);

this one works as well

Route::get('{whois}', $path.'getWhois')->where('whois', $aliases['whois']);

Typing in the url my_laravel.com/whois or my_laravel.com/who_is or my_laravel.com/quemsomos will send me to $path.'getWhois' (which is correct).

But when I try to call it in the html on blade...

<a href="{{ route('whois') }}">Who we are</a>

The reference link goes to my_laravel.com//%7Bwhois%7D

How could I call route('whois') on my blade.php and make it work like when I type it on the url ?

I would like to use the route function` in my blade, so I can keep a pattern.

Michel Ayres
  • 5,891
  • 10
  • 63
  • 97
  • would like help http://stackoverflow.com/questions/22751866/laravel-4-blade-templating-how-to-properly-link-to-route? – Dhiraj Mar 18 '15 at 13:01

1 Answers1

5

During route generation using the route function, Laravel expects you to set the value of the route parameter. You are leaving the parameter whois empty so the parameter capturing {whois} will not be replaced and results in the %7B and &7D for the accolades.

So in order to generate a route you will need to define what value you'd like to use for whois; {{ route('whois', ['whois'=>'whois']) }} for instance.

Luceos
  • 6,629
  • 1
  • 35
  • 65