8 months ago

Append query string to URL

Posted 8 months ago by iqlas

I am working on multi lingual application in Laravel (5.7)

I have a middleware Locale which is applied for all the web routes group and it checks if the locale is set for application and sets if not. Here to make the URL unique for each language, I want to add query string ?lang=en or as required.

I used the following in Locale middleware

public function handle($request, Closure $next)
        $lang=$request->query('lang') ? $request->query('lang') : 'en';
        array_merge($request->query(), ['lang' => $lang]);
        return $next($request);

The language is being set as required but the URL doesn't show the merged query string like /?lang=en

Can anyone suggest or guide me if there is a better way to implement this?

Please sign in or create an account to participate in this conversation.