Today we are going to understand laravel before and after middleware with example.
Let’s dive into it.
So, we know that laravel has middlewares which help us to filter or modify the https requests before they actually interact with the internal application features.
We are not going to discuss how we can generate the middlewares and register them to app\http\kernel.php
. Then it will be available to use on routes, route groups or in the controllers. That is already given in the laravel documentation.
Public function handle ($request, Closure $next) { // perform some operation before the closure call $response = $next($request); // perform some operation after the closure call Return $response; }
As we can see in the code above, it is that simple.
Before middleware means to perform some operations before processing the request. For example, add new data to the request or may be convert comma separated string to array etc. And after middleware means to perform the operations after processing the request and before returning the response. Then we can also manipulate or add new data to the response .
That’s it, laravel before and after middleware with example code.
Read also : PHP testing frameworks
Hope you enjoy the article, if so please feel free to share your thoughts about it in the comment section below.
Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…
Let's understand about how to use coding to improve your website's SEO. In today’s computerized…
Let's understand the most important linux commands for web developers. Linux, as an open-source and…
Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…
Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…
Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…