Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass instance of Request from a controller function to another controller function

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.

like image 717
Mohd Mobeen Avatar asked Mar 14 '18 09:03

Mohd Mobeen


People also ask

How do you call a post function in laravel?

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.

How to pass a request to another method?

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:

How do I get the instance of a controller?

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

What is an action in a controller?

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:

How do I request a service from a single action method?

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.


2 Answers

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.

like image 162
martin carrasco Avatar answered Oct 10 '22 07:10

martin carrasco


Change this line

$report ->Applications($request->except('cl_e_start_date'));

To

$report ->Applications($request);
like image 21
Sohel0415 Avatar answered Oct 10 '22 07:10

Sohel0415