I come across a situation in Laravel while calling a store() or update() method with Request parameter to add some additional value to the request before calling Eloquent fu
Based on my observations:
$request->request->add(['variable' => 'value']); will (mostly) work in POST, PUT & DELETE methods, because there is value(s) passed, one of those is _token. Like example below.
public function process(Request $request, $id){
$request->request->add(['id' => $id]);
}
But [below code] won't work because there is no value(s) passed, it doesn't really add.
PROCESS
public function process(Request $request, $id){
$request->request->add(['id' => $id]);
}
public function process($id){
$request = new Request(['id' => $id]);
}
Or you can use merge. This is better actually than $request->request->add(['variable' => 'value']); because can initialize, and add request values that will work for all methods (GET, POST, PUT, DELETE)
public function process(Request $request, $id){
$request->merge(['id' => $id]);
}
Tag: laravel5.8.11