这是我的路线档案:
Route::get('/', 'WebController@index');
Route::group(['prefix' => 'cn'], function () {
Route::get('/', 'WebController@index');
Route::group(['namespace' => 'ACL', 'prefix' => 'auth'], function () {
Route::get('login', 'AuthController@login');
Route::post('login', 'AuthController@login');
Route::get('logout', 'AuthController@logout');
});
Route::group(['middleware' => ['auth', 'token']], function () {
Route::get("/intentional", 'IntentionalOrderController@index');
Route::get("/intentional/add", 'IntentionalOrderController@create');
Route::post("/intentional/add", 'IntentionalOrderController@store');
Route::get("/intentional/selfOrder", 'IntentionalOrderController@selfOrder');
Route::post("/intentional/selfOrder", 'IntentionalOrderController@storeSelfOrder');
});
});
Route::group(['prefix' => 'en'], function () {
Route::get('/', 'WebController@index');
Route::group(['namespace' => 'ACL', 'prefix' => 'auth'], function () {
Route::get('login', 'AuthController@login');
Route::post('login', 'AuthController@login');
Route::get('logout', 'AuthController@logout');
});
Route::group(['middleware' => ['auth', 'token']], function () {
Route::get("/intentional", 'IntentionalOrderController@index');
Route::get("/intentional/add", 'IntentionalOrderController@create');
Route::post("/intentional/add", 'IntentionalOrderController@store');
Route::get("/intentional/selfOrder", 'IntentionalOrderController@selfOrder');
Route::post("/intentional/selfOrder", 'IntentionalOrderController@storeSelfOrder');
});
});
问题是:
当我输入/ en或/ cn url时,浏览器会说太多重定向;但是当我输入/ en / auth / login或任何其他网址时,它会正常工作。
虽然我可以通过将/ cn重命名为/ cn / index来解决这个问题,但我仍然不明白为什么这不起作用。
PS: 我的laravel版本是5.1 2.调试环境是笨拙的 3.浏览器是chrome
更新
这是我的WebController和BaseController
<?php namespace App\Http\Controllers;
class WebController extends BaseController
{
public function index()
{
return view(config('app.locale') . ".web.index", ["title" => trans('common.smart_fabric'), "active" => "0"]);
}
}
<?php namespace App\Http\Controllers;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
class BaseController extends Controller
{
public function __construct()
{
$locale = Request::segment(1);
if ($locale) {
switch ($locale) {
case 'cn':
App::setLocale('cn');
break;
case 'en':
App::setLocale('en');
break;
default:
App::setLocale('cn');
}
}
}