我正在尝试创建一个带有别名数组的路由,所以当我在url中调用whois或who_is时,它会转到相同的路径。
然后,我不需要每次都重复代码,只更改别名。
我试过下面的代码。
路由中的变量:
$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']);输入url my_laravel.com/whois、my_laravel.com/who_is或my_laravel.com/quemsomos将发送给$path.'getWhois' (这是正确的)。
但当我试图在刀刃上的html中调用它时..。
<a href="{{ route('whois') }}">Who we are</a>参考链接转到my_laravel.com//%7Bwhois%7D
当我在url上键入route('whois')时,我如何在blade.php上调用它并使其工作起来呢?
我想在我的刀片中使用route函数,这样我就可以保持一个模式。
发布于 2015-03-18 13:02:10
在使用route函数生成路由时,Laravel希望您设置路由参数的值。您的参数是空的,所以捕获{whois}的参数不会被替换,并导致%7B和&7D的荣誉。
因此,为了生成一条路由,您需要定义您想要为whois;例如{{ route('whois', ['whois'=>'whois']) }}使用的值。
https://stackoverflow.com/questions/29122727
复制相似问题