I have to call a function from one controller an other controller.
public function getquickviews(Request $request){
$report = new ReportController();
$report ->Applications($request->except('cl_e_start_date'));//it's not working its giving me error that it expect and instance of Request and passed array()
}
public function Applications(Request $request)
{
/*APP USAGE*/
}
and I have to pass instance of Request to Application function. But the issue I don't wanted to pass all the parameter from getquickviews Request like if I am getting email,phone,name on the getquickviews function but I only have to pass phone,email to Application function.
We can create a “Calling” function. Copy the actionable parts of the method into another function that can be called. In essence, you are creating a function that retrieves the data from the POST request and then calls the actual function that processes the data bypassing the data as a parameter.
Two ways to get requests into next method or any next level call. If you want to pass $request into other method for example to display data after insert you can do this way: or second is you can use request as metho into showStore or any n level call. Like this:
Instead, you should get an instance of your controller like this: var controller = DependencyResolver.Current.GetService<ControllerB>(); controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller); Share Follow edited Dec 27 '17 at 17:13
An action (or action method) is a method on a controller which handles requests. Controllers logically group similar actions together. This aggregation of actions allows common sets of rules, such as routing, caching, and authorization, to be applied collectively. Requests are mapped to actions through routing. By convention, controller classes:
If the service is needed by only a single action method, consider using Action Injectionto request the dependency. Within the Model-View-Controller pattern, a controller is responsible for the initial processing of the request and instantiation of the model.
You need to create a new instance of Request.
public function getquickviews(Request $request){
$report = new ReportController();
$content = new Request();
$content->something = $request->something;
$content->somethingElse = $request->somethingElse;
$report ->Applications($content);
}
and then you have to recieve it in:
public function Applications(Request $request)
{
/*APP USAGE*/
}
and that's it. Regards.
Change this line
$report ->Applications($request->except('cl_e_start_date'));
To
$report ->Applications($request);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With