Adding additional values in Request Laravel

When a form is submitted , we can get the form input in our controller using Request class or helper . Sometime’s we might need to add additional information to the request . There are several ways to add them .

Let’s look at the code :

Above function is for creating a post . Let’s say we want to add some additional data in request .

Adding additional data in request :

Another ways to add additional data :

Both above ways does the same thing adding additional user_id values in request . This last one is usually what i do when i need to add some data to the request .

This is some of the ways to add additional data to the request in Laravel . If there is any other ways , drop it in the comment section . Hope this was helpful 🙂 Happy coding 🙂

Sharing is caring!

Related Post