Files
InvoiceShelf/app/Traits/SiteApi.php
T

36 lines
891 B
PHP

<?php
namespace App\Traits;
use App\Models\Setting;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
// Implementation taken from Akaunting - https://github.com/akaunting/akaunting
trait SiteApi
{
protected static function getRemote($url, $data = [], $token = null)
{
$client = new Client(['verify' => true, 'base_uri' => config('invoiceshelf.base_url').'/']);
$headers['headers'] = [
'Accept' => 'application/json',
'Referer' => url('/'),
'Authorization' => "Bearer {$token}",
'invoiceshelf' => Setting::getSetting('version'),
];
$data['http_errors'] = false;
$data = array_merge($data, $headers);
try {
$result = $client->get($url, $data);
} catch (GuzzleException $e) {
$result = null;
}
return $result;
}
}