I need to return in a method of my controller to a post route sending its request with the parameters that the function receives, this is what I have in my controller:
public function miFunciondeControlador()
{
$parametro1 = "valor1";
$parametro2 = "valor2";
$parametro3 = "valor3";
$request_enviar = new Request();
$request_enviar->setMethod('POST');
$request_enviar->request->add(['parametro1' => $parametro1,'parametro2' => $parametro2,'parametro3' => $parametro3 ]);
//Necesito algo parecido a esto para llamar a esta ruta que es post que recibe un request
return redirect()->route('miruta', ['request' => $request_enviar ]);//No funciona
}
In the routes file this is the route I need to call:
Route::post('/miruta','miController@metodoCualquiera')->name('miruta');
This is how the function I'm trying to call receives the parameters:
public function metodoCualquiera(Request $request)
{
$parametro1 = $request->parametro1;
$parametro2 = $request->parametro2;
$parametro3 = $request->parametro3;
dd($request); //Imprime Vacio
}
I don't know what you are trying to do with a kind of redirection to a POST, but I dare to say that it is a bad practice, it is as if you were trying to communicate with two controllers, but you also add an ingredient which is the HTTP Request.
By design conventions, if two methods of one or more controllers need to use the same "code", then that code must be in another layer, it can be a model, service, repository, interface, trait, etc.
That said, we would have three protagonists and we are going to use DI:
The service that receives the information from both methods and/or controllers
The first method you show
The second method, the one that receives the POST
Don't forget to add the
use App\Services\MiServicio;
respective ones.