lundi 1 janvier 2018

Laravel implementing simple MiddleWare don't work

in my web application i'm trying to check local in urls, for example:

in this url as http://ift.tt/2C6cWMx we don't have any locale such as en,ru or etc for example: http://ift.tt/2CCa3Ee.

in my web app i implemented simple middleware to check that and fix url when urls doesn't have them:

class language
{
    public function handle($request, Closure $next)
    {
        dd($request);
        $locale = $request->segment(1);

        if (!array_key_exists($locale, config('app.locales'))) {
            $segments = $request->segments();
            $segments[0] = config('app.fallback_locale');
            return redirect(implode('/', $segments));
        }

        app()->setLocale($locale);

        return $next($request);
    }
}

which that registered into:

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\Language::class,
        ...
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];
protected $routeMiddleware = [
    'language' => \App\Http\Middleware\Language::class,
    ...
];

this middleware only work when we have locale in url and my code as:

Route::get('/showContent/aboutUs', ['middleware' => 'language', function()
{
    dd('asda');
    //
}]);

dont work and i dont see any dd output

1:

Route::group(['middleware' => 'web'], function () {
    Route::get('/showContent/aboutUs', 'HomeController@aboutUs');
});

2:

Route::group(['middleware' => 'language'], function () {
    Route::get('/showContent/aboutUs', 'HomeController@aboutUs');
});

for all my solutions i get this output:

Sorry, the page you are looking for could not be found.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lAn4XO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire