Level 9
$request->merge(['lang' => config('global.default_locale')]);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi
Is it possible to sign the protected property of an object?
public function handle($request, Closure $next)
{
if ($request->filled('lang')) {
$tmpRow = TableName::where('locale', '=', $request->input('lang') )->first();
if ( !$tmpRow ) {
$request->lang = config('global.default_locale');
}
}
return $next($request);
}
I mean checking if the 'lang' parameter value is one of the values given in the database, and if not to change the value in the request to the default language of the page. I wanted to do this through midellware that it worked globally, not that I had to overwrite every method on the site.
$request->merge(['lang' => config('global.default_locale')]);
Please or to participate in this conversation.