Difference between Request (Facade) and Illuminate\Http\Request
Asked Answered
D

2

7

I'm starting to use Laravel and I would like to know how I should choose one over the other.

As of version 5.0 Laravel documentation changed request example from Request::get('form_input') to $request->get('form_input'), but I couldn't find any explanation as for why they've done that.

My doubts are:

  1. Is there any difference between those Requests?
  2. Whare are they?
  3. What's the most prefered?
Deluxe answered 10/2, 2017 at 12:7 Comment(0)
C
2

Straigth answer: No (particular difference) Except that: Referencing from this source, How laravel facades work and how to use

A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container’s services.

I couldn't agree more with this. But as for me, using facade pattern simply make my code cleaner :)

Constitute answered 10/2, 2017 at 13:14 Comment(0)
K
2

The Request facade and the request() helper refer both to app('request') instance. I think the examples in docs changed to $request because you can define your own Request derived class and the service container will automatically inject it in the action call, like in the case of FormRequest, i.e.:

public function store(UserStoreRequest $request)
{
    $name = $request->input('name');
Kepner answered 10/2, 2017 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.