2016-12-26 12 views
1

I View Composerを書き込もうで使用$要求、View Composerの

class CountryCodeComposer 
{ 

    function compose($view) 
    { 
     $code = substr(file_get_contents('http://ipinfo.io/' . $request->getClientIp() . '/country'), 0, 2); 
     $view->with('code', $code); 
    } 
} 

が、このコードのショーのエラーUndefined variable: request

がどのようにメソッドを構成する$requestを渡すことができますか?

答えて

3

$request->getClientIp()request()->getClientIp()

+0

と交換してください。私は、エラーメッセージ「静的なメソッドのIlluminate \ Http \ Request :: server()を静的に呼び出すべきではありません。」を表示していました。これで解決されました。 –