Search code examples
laravelhttprequest

Class 'Illuminate\Support\Facades\Http' not found in Laravel 7.x


In my Laravel app and as a scheduled task, I want to make an Http request in my custom class but I get

Class 'Illuminate\Support\Facades\Http' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'Illuminate\\Support\\Facades\\Http' not found

Here is my custom class

<?php

namespace App\MyModels\GetData;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class Test
{
    public function __invoke()
    {
        Log::info("Cron executed : ");
        $response = Http::get("https://google.com");
        Log::info(print_r($response, true));
    }
}

in Laravel documentation, it says :

To make requests, you may use the get, post, put, patch, and delete methods. First, let's examine how to make a basic GET request:

use Illuminate\Support\Facades\Http;

$response = Http::get('http://test.com');


Solution

  • For me, the issue had to do with the fact that (while I thought the project was on version 7 for Laravel) I appeared to be on version 6.x for Laravel. Updated to the newest version solved this issue for me. Link to the GitHub issue that resolved my issue

    Although the question is specific about version 7 I still feel this might help some people