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

frkiergn's avatar

Middleware complexity

Hi, As someone who has been using Codeignter 4 for years, I started using laravel for a new project. But there is a subject that I have difficulty understanding. For example, when I want to use a session in my project, I first need to define the StartSession file in the middleware function of the bootstrap\app.php file. otherwise the sessions I create are not saved in any way. I understand this in a way. The Framework takes a minimalist approach and wants me to define what I need. But when it asks me to use $middleware->append() command, I can't see the flash sessions and validation data. Every time I refresh the page, the session id changes and a lot of session files are created. I spent almost a day and no video I watched, no article I read could solve my problem. But I was able to solve this problem with a comment on one site (by changing $middleware->web() instead of $middleware->append()) and I could not see it in any Laravel article. (I may have missed it.) What is the logic of append(), prepend() or use()? Why should I use or not use them. and why can't I see an explanatory article on this subject or I'm missing it.

0 likes
1 reply
jlrdw's avatar

Look at the various chapters:

  • middleware
  • controller middleware in controller chapter
  • routing middleware in routing chapter

And the 30 days to learn laravel 11 free course.

Please or to participate in this conversation.