Home > database >  ¿How to create a custom FormRequest from normal Request?
¿How to create a custom FormRequest from normal Request?

Time:01-13

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.

CodePudding user response:

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.

  •  Tags:  
  • Related