Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ejobity's avatar

Whats the difference between using request('id') and $request->id

I would like to know what is the difference between using request('id') and $request->id.

An example:

function ()
{
    $idnumber = request('id');
}
function (Request $request)
{
    $idnumber = $request->id;
}

What are the affects between the two if any?

0 likes
1 reply
Jaytee's avatar
Jaytee
Best Answer
Level 39

There is only one difference.

request() is a helper method. It essentially just allows you to call it anywhere without needing to inject the request through the method arguments. It's also much easier to use.

$request is used from the injection, function (Request $request).

Oh, it also means you don't need to import the request class at the top of your file.

You can also do:

request('name'),
request()->name,
request()->input('name')
$request->name
$request->input('name')

Just like other methods that you'll use, it's for convenience. view() is a helper method, it saves you from needing to do View::make('view.name');

1 like

Please or to participate in this conversation.