我正在尝试创建一个带有别名数组的路由,这样当我在url中调用whois或who_is时,它会进入同一个路由。然后我就不需要每次重复编写代码,只需更改别名即可。
我尝试了下面的代码。
路由中的变量:
这个也可以运行。
参考链接指向
我想在我的blade中使用
我尝试了下面的代码。
路由中的变量:
$path = 'App\Modules\Content\Controllers\ContentController@';
$aliases['whois'] = '(quemsomos|who_is|whois)';
路由:
Route::get('{whois}', array('as' =>'whois', 'uses' => $path.'getWhois'))->where('whois', $aliases['whois']);
这个也可以运行。
Route::get('{whois}', $path.'getWhois')->where('whois', $aliases['whois']);
在浏览器地址栏中输入 my_laravel.com/whois
或 my_laravel.com/who_is
或 my_laravel.com/quemsomos
将会跳转到 $path.'getWhois'
(这是正确的)。
但是,当我尝试在blade模板中调用它时...
<a href="{{ route('whois') }}">Who we are</a>
参考链接指向
my_laravel.com//%7Bwhois%7D
我该如何在blade.php中调用route('whois')
并使其像在URL上输入时一样正常工作?我想在我的blade中使用
route
函数,这样我就可以保留一个模式。