123movies-seo/app/Http/Middleware/AddLinkHeadersForPreloadedFonts.php

27 lines
704 B
PHP
Raw Normal View History

2024-08-24 23:08:42 +03:00
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Collection;
class AddLinkHeadersForPreloadedFonts
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, $next)
{
return tap($next($request), function ($response) {
if (config('fonts') !== []) {
$response->header('Link', Collection::make(config('fonts'))
->map(fn ($url) => "<{$url}>; " . 'rel="preload"; as=font; type="font/woff2"; crossorigin')
->join(', '));
}
});
}
}