initial commit
This commit is contained in:
47
app/Utility/Curl.php
Normal file
47
app/Utility/Curl.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utility;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Curl
|
||||
{
|
||||
private array $prepareData;
|
||||
private static string $url;
|
||||
private static array $header;
|
||||
|
||||
public function __construct($url,$header = ['Content-Type: application/json']){
|
||||
static::$url = $url;
|
||||
static::$header = $header;
|
||||
}
|
||||
|
||||
private function prepareRequest($inputData){
|
||||
return $inputData;
|
||||
}
|
||||
|
||||
public function post($request){
|
||||
|
||||
$this->prepareData = $this->prepareRequest($request);
|
||||
|
||||
$response = Http::withHeaders(static::$header)
|
||||
->post(
|
||||
static::$url,
|
||||
$this->prepareData
|
||||
);
|
||||
|
||||
return json_decode((string) $response->getBody(), true);
|
||||
}
|
||||
|
||||
public function get($request){
|
||||
|
||||
$this->prepareData = $this->prepareRequest($request);
|
||||
|
||||
$response = Http::withHeaders(static::$header)
|
||||
->get(
|
||||
static::$url,
|
||||
$this->prepareData
|
||||
);
|
||||
|
||||
return json_decode((string) $response->getBody(), true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user