Skip to content

Glossary

Laravel middleware: the layer in front of the actual request

Code every request passes before it reaches its destination, for signing in, permissions or logging.

Between the incoming request and the code that answers it lies a chain of layers. Each one can inspect the request, change it, let it through or turn it away. In Laravel such a layer is called middleware.

Typical questions answered there: is the caller signed in? Do they hold the necessary role? Did the request come from a form on this site? How many calls came from this IP address in the last minute?

Why this is the right place

The rule exists once and applies to every route underneath it. Middleware demanding a sign-in for the whole administration area cannot be forgotten when a new page is added.

This is where many applications come unstuck. The check sits in the interface, a button gets hidden, and the address behind it stays open. What we keep running into on this is in the article what keeps turning up in Laravel audits.

FAQ

Häufige Fragen

Does middleware replace permission checks in the code?
It is the first line of defence, not the only one. Coarse questions such as “signed in or not” belong in middleware. Finer ones such as “may this user change exactly this record” belong in a policy right at the access.

Related

Terms that belong with this one

A project, or a question?

Write and tell us what it is about. You get an assessment from somebody who works with Laravel themselves, not from a sales desk.