Tuesday, March 14, 2017

Why "Request::" (Request Static class) gives me different methods from $resquest-> (Request object) in Laravel 5.4?

I was trying to grab the current path that was asked by the user. Following the doc I have created these 2 methods:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use GuzzleHttp\Client;

class TestController extends Controller
{
    public function reqTest1(Request $req) {
        dd($req->path());
    }
    public function reqTest2() {
        dd(Request::path());
    }
}

The reqTest1 works good, but I had to inject the Request object inside the function. There I can grab path() method, and I have the response as expected.

But if I dont wan to inject dependencies I should be able to get the same method only calling the static class Request. (I dont know).

I just realise that we dont have the same methods available in these 2 scenarios.

The methods list for the injected object is much bigger than the static class that generate the same object, for the Request class..

So, why Request class has different methods from a Request object created by a dependency injection?



via zwitterion

Advertisement