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

내가 생성자 파라미터에 액세스 할 수 하워드? 이 방법으로 문제가 해결 될 경우 내가보기

+1

laravel 4.2을 사용하고 있습니다 : https://stackoverflow.com/questions/25766894/is-it-possible-to-pass-a-route-parameter-to-controller -constructor-in-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]") 
관련 문제