34 lines
718 B
PHP
34 lines
718 B
PHP
<?php
|
|
|
|
namespace Silva\Adrema\Support;
|
|
|
|
use Silva\Adrema\Models\Settings;
|
|
use Http;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class Proxy
|
|
{
|
|
public function run(string $url): ?array
|
|
{
|
|
$response = Http::acceptJson()->get($this->url($url));
|
|
|
|
if (!$response->ok()) {
|
|
return null;
|
|
}
|
|
|
|
return $response->json();
|
|
}
|
|
|
|
public function submit(string $url): JsonResponse
|
|
{
|
|
$response = Http::acceptJson()->post($this->url($url), request()->input());
|
|
|
|
return response()->json($response->json(), $response->status());
|
|
}
|
|
|
|
private function url(string $internal): string
|
|
{
|
|
return Settings::get('base_url') . str($internal)->start('/');
|
|
}
|
|
}
|