2024-08-16 16:25:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-27 16:49:43 +02:00
|
|
|
namespace App\Http\Controllers\Content;
|
2024-08-16 16:25:13 +02:00
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-08-27 16:49:43 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-08-16 16:25:13 +02:00
|
|
|
|
|
|
|
|
class FontsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
2024-08-27 16:49:43 +02:00
|
|
|
if (!config('services.google.fonts_api_key')) {
|
|
|
|
|
return response()->json([]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-16 16:25:13 +02:00
|
|
|
return \Cache::remember('google_fonts', 60 * 60, function () {
|
2024-08-19 15:22:57 +02:00
|
|
|
$url = "https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=" . config('services.google.fonts_api_key');
|
2024-08-16 16:25:13 +02:00
|
|
|
$response = Http::get($url);
|
|
|
|
|
if ($response->successful()) {
|
|
|
|
|
$fonts = collect($response->json()['items'])->filter(function ($font) {
|
|
|
|
|
return !in_array($font['category'], ['monospace']);
|
|
|
|
|
})->map(function ($font) {
|
|
|
|
|
return $font['family'];
|
|
|
|
|
})->toArray();
|
|
|
|
|
return response()->json($fonts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|