1

I have two controllers (Workflow and Stage), I need to route to Stage.store function from the Workflow.store function using a request object I have been created :

Workflow controller:

public function store(WorkflowRequest $request)
{
    $oWorkflow = new WfWorkflow();
    $oWorkflow->name = $request->get('workflow_name');
    if($oWorkflow->save()){
        $aStages = $request->get('wf_stage');
        $params = [
            '_token' => $request->get('_token'),
            'wf_id' => $oWorkflow->id,
            'stages' => $aStages
        ];
        $oStageRequestObject = Request::create(url('stage'), 'POST', $params);
    }
}

Now, how can i use the Request object $oStageRequestObject to route to stage.store using POST method ?

  • In stage.store i need to use form request validation.

2 Answers 2

2
$params = [
        '_token' => $request->get('_token'),
        'wf_id' => $oWorkflow->id,
        'stages' => $aStages
    ];

You want to send this $params variable to route to stage.store using POST method .

For that you can set session .

For ex.

In Workflow.store method set session like this.

Session(['param' => $params]);

Now you can access this session in stage.store method using POST method .

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to reuse stage.store logic, then I would suggest to create StageService service class that handles this logic. So StageController would look like this:

public function store(Requests\StoreStageRequest $request, StageService $stageService)
{
    $stageService->handleRequest($request); // put controller logic to this function

    return redirect('/somewere');
}

And then in WorkflowController you may manually create StoreStageRequest request and pass it to handleRequest():

public function store(WorkflowRequest $request, StageService $stageService)
{
    // ...

    $params = [
        '_token' => $request->get('_token'),
        'wf_id' => $oWorkflow->id,
        'stages' => $aStages
    ];

    $oStageRequest = new Requests\StoreStageRequest($params);

    $stageService->handleRequest($oStageRequest);

    // ...
}

As for validation, think the only way is to manually create Validator, and pass to it data and rules.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.