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 :
public function store(Request $request)
Above function is for creating a post . Let’s say we want to add some additional data in request .
Adding additional data in request :
'user_id' => auth()->id() ]);
Another ways to add additional data :
$request = $request->all()
$request['user_id'] = auth()->id();
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 .
'user_id' => auth()->id()
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 🙂