2016-05-31 84 views
0

基本上我想做的就是自動更改de前綴,所以我只有一個視圖。鏈接可能看起來像這樣。Laravel - 寫什麼來獲取當前前綴{{URL :: to('prefix/search')}}

{{URL::to('california/search')}} 
{{URL::to('florida/search')}} 
{{URL::to('arkansas/search')}} 

我使用Laravel 5.2

這是控制器我使用:

//Controllers for states 
Route::group(array('prefix' => 'california', "namespace" => 'Test'), function() {  
    Route::get("/all", "[email protected]"); 
    Route::get('/search',['uses' => '[email protected]','as' => 'search']); 
    Route::get('/show/{id}', '[email protected]'); 

}); 
Route::group(array('prefix' => 'florida', "namespace" => 'Test'), function() {  
    Route::get("/all", "[email protected]"); 
    Route::get('/search',['uses' => '[email protected]','as' => 'search']); 
    Route::get('/show/{id}', '[email protected]'); 

}); 
Route::group(array('prefix' => 'arkansas', "namespace" => 'Test'), function() {  
    Route::get("/all", "[email protected]"); 
    Route::get('/search',['uses' => '[email protected]','as' => 'search']); 
    Route::get('/show/{id}', '[email protected]'); 

}); 

回答

2

根據用於RequestRoute如下因素代碼Laravel API文檔檢索當前路由前綴

Request::route()->getPrefix() 
+0

謝謝你,這是我需要的。 –

+0

該解決方案是否有效? – huuuk

1

這就是我解決問題的方法。

{{URL::to(Request::route()->getPrefix().'/search')}} 

如果這樣做更有意義。

<?php $prefix = Request::route()->getPrefix(); ?> 
{{URL::to($prefix.'/search')}}