简体   繁体   中英

Laravel: Use two Requests at the same time in a controller

I have a function in my controller. The problem is I must use two Requests at the same time but only one of them can be used in a controller.

  • Illuminate\\Support\\Facades\\Request
  • Illuminate\\Http\\Request

Code:

public function func(Request $req) {
    if (Request::isMethod('post')) {
        $this->validate($req, [
            'username' => 'required|string'
        ]);
    }
}

What is the solution?

If you wanted to use both of them, you can alias them as below:

use Illuminate\Http\Request as RequestNew;
use Illuminate\Support\Facades\Request as RequestOld;

And then you can reference the alias in your code.

eg: RequestNew::isMethod('post')

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