1

嗨,我有多语言网站的问题。我有 laravel 5.5,我安装了 Laravel-Translatable。

当他要打开主页时,地址显示:project/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en /en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en

我现在不知道,为什么有一个地址。

我的中间件/Language.php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;

class Language
{
public function handle(Request $request, Closure $next)
{
    // Check if the first segment matches a language code
    if (!array_key_exists($request->segment(1), config('translatable.locales')) ) {

        // Store segments in array
        $segments = $request->segments();

        // Set the default language code as the first segment
        $segments = array_prepend($segments, config('app.fallback_locale'));

        // Redirect to the correct url
        return redirect()->to(implode('/', $segments));
    }

    return $next($request);
}
}

我的 web.php(路由)

Route::get('/', 'PagesController@getIndex');

和我的 PagesController.php

class PagesController extends Controller
{
    public function getIndex() {

        $this->data['menu_items'] = MenuItem::getTree();
        return view('pages.index', $this->data);
    }
}
4

0 回答 0