2

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?

Mahmood Kohansal
  • 1,021
  • 2
  • 16
  • 42
  • You need to specify what you mean by "request". Do you mean you want to use both *types*, you need two instances or you actually mean you want to process two (2) http requests at the same time? – Mark Mar 21 '16 at 17:01

1 Answers1

3

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')

Jilson Thomas
  • 7,165
  • 27
  • 31
  • 1
    See using aliases in namespaces: http://php.net/manual/en/language.namespaces.importing.php – Mark Mar 21 '16 at 17:02