Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Request classes

Laravel 5.1 has the following classes that seems to share the same name and some have similar behavior.

use App\Http\Requests\Request;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Input;

What are the differences between the Request classes and when should we use each class?

like image 854
Yada Avatar asked Jul 31 '15 12:07

Yada


2 Answers

If you look at http://laravel.com/docs/5.1/facades you see that both the Input facade as the Request facade are facades of the class:

Illuminate\Http\Request

The App\Http\Requests\Request you're talking about is the same class. There is one minor difference in the facades for Request and Input. See this post about the exact difference https://stackoverflow.com/a/29961400/1129489

like image 69
Remko Avatar answered Oct 04 '22 01:10

Remko


Here is the tl;dr from the answer at https://stackoverflow.com/a/29961400/1129489

  1. Don't use the Input class. It's the same as Facases\Request and is there for legacy reason.

As for my own code base I'm going to use the following convention:

use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Facades\Request;
like image 32
Yada Avatar answered Oct 04 '22 02:10

Yada