2017-12-18 164 views
0

我試圖訪問構造函數中的路由器參數,但沒有運氣我已經嘗試使用Route::getParameter('template')Route::input('template')但都返回null,如果我訪問控制器函數中的參數,它顯示正確的值訪問路由器參數控制器的構造函數

public function myFunction($template){ 
    return $template; 
    //This show the value 
    //return Route::getParameter('template'); this show null 
    //return Route::input('parameter'); this show null too 
} 

//My route 
Route::get("my-route/{template}","[email protected]") 

霍華德我可以訪問參數的構造函數?我使用laravel 4.2

+1

看看這個解決您的問題:https://stackoverflow.com/questions/25766894/is-it-possible-to-pass-a-route-parameter-to-controller -constructor功能於laravel –

回答

0
Add default parameter in function Request $request then add template. 

    public function myFunction(Request $request, $template){ 
     return $template; 
     //This show the value 
     //return Route::getParameter('template'); this show null 
     //return Route::input('parameter'); this show null too 
    } 

    //My route 
    Route::get("my-route/{template}","[email protected]")