Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In laravel 10 there is no $routeMiddleware #867

Open
engmonged opened this issue Apr 28, 2023 · 2 comments
Open

In laravel 10 there is no $routeMiddleware #867

engmonged opened this issue Apr 28, 2023 · 2 comments

Comments

@engmonged
Copy link

In laravel 10 there is no $routeMiddleware where can i put this
/**** OTHER MIDDLEWARE ****/
'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
'localeCookieRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class

@alihan0
Copy link

alihan0 commented May 3, 2023

In laravel 10 there is no $routeMiddleware where can i put this /**** OTHER MIDDLEWARE ****/ 'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class, 'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class, 'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class, 'localeCookieRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class, 'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class

There is no protected $routeMiddleware [...] for Laravel 10.x.

To run, you can add it to protected $middlewareGroups[...] or protected $middlewareAliases[...] in app/http/kernel.php. either way will work, just if you prefer to add in group you have to change our usage as follows.

app/http/kernel.php

protected $middlewareGroups = [
       ....
      'localize' =>[
                    \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
                    \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
                    \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
                    \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
                    \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class
             ] 
];

routes/web.php

Route::group(
[
	'prefix' => LaravelLocalization::setLocale(),
	'middleware' => [ 'localize' ]
], function(){ //...
});

On the other hand, despite the installation, localization within the blade templates worked fine but not within the controller. I've been searching for a solution to this for a few days and realized that the problem was url redirection. Although the sessions change, the setLocale() method does not work as it should. I found a workaround for this,

axios.post( '{{ \LaravelLocalization::localizeURL("/auth/login/control") }}', {...} this way, manually changing the request urls I make to my controllers works.

Sorry for bad English ^^ Good Code!

@igramnet
Copy link

igramnet commented Jul 10, 2023

I added code to $middlewareGroups

`

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \App\Http\Middleware\RedirectTrailingSlash::class,
    ],
    'api' => [
        // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        \Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
    /**** OTHER MIDDLEWARE ****/
    'localize' => [
        \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
    ],
    'localizationRedirect' => [
        \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
    ],
    'localeSessionRedirect' => [
        \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
    ],
    'localeCookieRedirect' => [
        \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
    ],
    'localeViewPath' => [
        \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,
    ],

];

`

Everything is okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants