Laravel-Translatable home page url duplicate

118 Views Asked by At

Hi I have problem with multilanguage website. I have laravel 5.5, and I install Laravel-Translatable.

When he wants to turn on the main page, the address is displayed: 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

I don't now, why is there an address.

My Middleware/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);
}
}

My web.php (routing)

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

and my PagesController.php

class PagesController extends Controller
{
    public function getIndex() {

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

There are 0 best solutions below