简体   繁体   中英

How to call a Request function from a controller to another controller in Laravel

How to call a Request function from a controller to another controller in Laravel

Controller1.php

public function get(){

$call = new Controller2();

$input = new Request();
$input->param1 = param1;
$input->param2 = param2;

$response = $call->index($input)

}

Controller2.php

public function Index(Request $request){
dd($request->all());
}

I am getting [] as response.

in the symphony request class:

/**
     * Retrieve an input item from the request.
     *
     * @param  string|null  $key
     * @param  mixed  $default
     * @return mixed
     */
    public function input($key = null, $default = null)
    {
        return data_get(
            $this->getInputSource()->all() + $this->query->all(), $key, $default
        );
    }

you cannot get those variables by just calling ->input()

I recommend to not use the Request Object for these purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM