Have you tried debugging it? Especially the trans() function to see what happens.
On another note, are you sure you want to set the pageTitle in middleware? Why not translate in the view?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I had a strange reaction on middleware. I have created a middleware and assign it in web group and updated it as below (code cleared to focus problem). The problem is when i use this middleware session and csrf tokens are not created again. If i remove trans function and use a static value it works fine. I have installed a fresh laravel and got same results.
Anyone have a clue what is going on here?
Thanks and Regards...
public function handle($request, Closure $next)
{
$pageTitle = trans('title.for.home');
$response = $next($request);
return $response;
}
Please or to participate in this conversation.