In one of the training tutorials , I saw this code in LoginController but I don’t understand why except(‘logout’) is used.
Could you please explain it to a beginner?
What does except(‘logout’) mean?
I understand that something is excluded from the selection but I can’t for some reasonю
Advertisement
Answer
What is middleware?
I will explain it a little bit different.
Let’s say you want to enter into a room, but before that, you need to unlock the door and enter inside the room. The door is your middleware, you need to successfully unlock the door to enter inside the room. If you can’t unlock the door, your access will be forbidden. What is it mean except
word. You have two rooms one with a door and one without door, in this case logout
is the room without door and you can access to her without any key or you don’t need to unlock the door, for other one you need to successfully unlock the door and then go inside the room. I hope you understand, but if you have any questions, i will try to anser them. With except word you say attach this middleware to every route, and leave logout open, so if you try to access every other route, first your code will execute middleware and after that will execute your method, but for logout , you will execute lgout method directly without middleware