lets assume i have a website
www.example.com
and admin dashboard:
www.example.com/admin/*
i need to force locale language for all routes of admin/
to english
all admin routes located in routes/admin.php
what i have already tried:
Route::group(['middleware' => 'auth:admin'], function() {
App::setLocale( 'en');//**not working**
app()->setLocale('en');//**not working**
//other routes of admin
});
and tried this and also not working: in the app/http/kernel.php
protected $middlewareGroups = [
'admin' => [
AppHttpMiddlewareLocalizationAdmin::class,
],
];
where the LocalizationAdmin
class is:
<?php
namespace AppHttpMiddleware;
use Closure;
class LocalizationAdmin
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$locale='en';
app()->setLocale($locale);
return $next($request);
}
}
2
Answers
Edit your middleware function like this, you can set your app locale for all your routes that are admin in the first segment:
Remember to make sure you use the middleware for your related routes.
First create new middleware
In the middleware
Register it
$routeMiddleware
(pathapp/Http/Kernel.php
)In the route group call