Ad

¿How To Create A Custom FormRequest From Normal Request?

- 1 answer

I find something lost...

The problem

I need to construct 2 custom FormRequest from 1 normal Request Let's suppose this fake scenario

First FormRequest

StoreClientRequest

Second FormRequest

UpdateClientRequest

On the Controller:

public function store(Request $request){
    //Do something...
    $firstRequest = new StoreClientRequest($request);
    $secondRequest = new UpdateClientRequest($request);
}

Are there way to make something similar to this fake scenario.

Ad

Answer

If you really want to get an instance of your Form Requests, without resolving them from the IoC Container, you could use the createFrom method:

$firstRequest = StoreClientRequest::createFrom($request);

This will make sure it is filled with the same data as $request.

Ad
source: stackoverflow.com
Ad