2016-06-01 75 views
1

我有一個前綴路由組,我將採取這些前綴值爲不同的路由組顯示不同的頭部,所以我如何獲得只有前綴值,並可能把一些如果在我看來?獲取laravel前綴組的值

我有航線組這樣

Route::group(array('prefix' => 'cu'), function(){ 
    Route::get('login',array('as' => 'cu.login','uses' => '[email protected]_public')); 
    Route::post('login',array('as' =>'cu.login.post','uses' => '[email protected]_public')); 
    Route::get('logout',array('as' => 'cu.logout','uses' => '[email protected]_public')); 
}); 

我那麼如何在我的觀點得到cu價值? 注:我仍在使用laravel 4.2

編輯: 正如我之前所說,我仍然使用laravel 4.2和大多數解決方案getprefix不會在這裏工作...所以也許有另一種方法?

+0

的可能的複製[Laravel - 怎麼鑑於寫來獲取當前的前綴{{網址::到( '前綴/搜索')}}](HTTP:/ /stackoverflow.com/questions/37538327/laravel-what-to-write-in-view-to-get-current-prefix-urltoprefix-search) – huuuk

回答

1

請嘗試以下兩種:

$pref = $this->getRouter()->getCurrentRoute()->getPrefix(); 

和:

public function action(Request $request) 
{ 
    $pref = $request->route()->getPrefix(); 
} 

然後通過$pref到一個視圖並使用它。這項工作5+,但不知道4.2。

4.2試試這個:

@if (\Request::is('some_prefix/*')) 

@endif 
+0

沒有它不工作laravel 4.2 –

+0

我已經更新了我的答案,請嘗試其他解決方案 –

+1

哇感謝...它的工作原理...這是我尋找在互聯網這幾天最簡單的解決方案....感謝很多人! –