2017-12-18 168 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]")