php – Can you use a middleware on a POST or any other request?-ThrowExceptions

Exception or error:

In Laravel, I can’t really see anywhere using middlewares on any other request than a GET request, is it normal to use a middleware on a POST or PUT for example?

How to solve:

Yes, it’s perfectly valid to attach a middleware layer to any kind of requests. Middlewares are a way to add a layer of filtering to check whether the current request fulfills the requirements. It is completely unrelated to the type of HTTP verb of the request and is highly dependent on the purpose the request.

Answer´╝Ü

Yes, you can use middleware for post request. Laravel’s default authentication is an example of using middleware for post request

Leave a Reply

Your email address will not be published. Required fields are marked *