Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ymutlu's avatar

Session fail when trans function used

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; 
}
0 likes
2 replies
renedekat's avatar

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?

ymutlu's avatar

There is no error with trans function and it returns a valid string. I used middleware to change page title for diffrent routes. I am checking for parameters to update page title. There might be a better place to do that but i wonder about the problem.

Please or to participate in this conversation.