2017-08-31 28 views
0

でロケールを持つ接頭辞の後に私はPHPの職人が仕える実行url.Whenベースでロケールを接頭辞にしたいし、私はルートNotFoundHttpException Laravel 5.4でLaravel

notfoundhttpexception

を取得します。私が手作業で置くとうまくいきますhttp://localhost:8000/en。私は今何を望んでいる、私はPHPの職人を実行するときにそれはhttp://localhost:8000/enにリダイレクトする必要があります。

Route::group(['prefix' => App::getLocale() ], function() 
{ 
    Route::get('/', array('as' => 'home.index', 'uses' => '[email protected]')); 

}); 

答えて

0

私が正しくあなたの問題を理解していれば、あなたはこのようなコードを使用する必要があります:後

は、ルートファイルです

Route::group(['prefix' => '{locale}' ], function() 
{ 
    Route::get('/', array('as' => 'home.index', 'uses' => '[email protected]')); 
    //Setup locale based on request... 
    App::setLocale(Request::segment(1)); 
}); 

しかし、私はお勧めできる良い方法は以下のように使用したロケールの設定です:

if (in_array(Request::segment(1), ['en', 'fr'])) { 
    App::setLocale(Request::segment(1)); 
} else { 
    // set your default local if request having other then en OR fr 
    App::setLocale('en'); 
} 

と同じようにルートを呼び出す:

Route::group(['prefix' => '{locale}' ], function() 
{ 
    Route::get('/', array('as' => 'home.index', 'uses' => '[email protected]')); 
}); 

このコードでは、ルートプレフィックスに基づいてロケールを動的に設定できます。