How to create a request object in laravel 5.1?

0

I need to have a request in laravel 5.1, but I need to create it from php and not from a form. What I'm trying to do is call a laravel function to regain user passwords from my own controller

private function sendEmailWithPassword($objUser)
{
//Se crea variable de request
Request $request;

//Se crea la propiedad email
$request->request->add(['email' => $objUser->Person->Email]);

//Se llama función de laravel
$this->PasswordController->postEmail($request);
}

I tried to create a request in the following way

Request $request;

but I get the following error

syntax error, unexpected '$request' (T_VARIABLE)

In a few words I do not believe the variable, someone can help me

    
asked by Alejo Florez 12.02.2018 в 17:17
source

1 answer

2

It is not the correct way to create a variable of type Request , just as its code PHP tries to look for a data type Request for which it does not find result and throws the error.

Being a class Request , you should create an instance and assign it to the variable.

private function sendEmailWithPassword($objUser)
{
    //Se crea variable de request
    $request = new Request();

    //Se crea la propiedad email
    $request->request->add(array('email' =>$objUser->Person->Email));

    //Se llama función de laravel
    $this->PasswordController->postEmail($request);
}
    
answered by 12.02.2018 / 17:34
source