Files
FlightsAPI/app/Http/Controllers/Controller.php
T
2026-05-21 22:52:16 +10:00

25 lines
751 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Storage;
abstract class Controller
{
public function imageIfExists(string $path, $cacheLimit = 60 * 60 * 72){
if(!Storage::disk('local')->exists($path)){
return response()->json(['error' => 'Image not found'], 404);
}
$fullPath = Storage::disk('local')->path($path);
$lastModified = filemtime($fullPath);
return response()->file($fullPath, [
'Content-Type' => 'image/png',
'Cache-Control' => 'public, max-age='.$cacheLimit, // 24 hours
'Last-Modified' => gmdate('D, d M Y H:i:s', $lastModified) . ' GMT',
'ETag' => md5($path . $lastModified),
]);
}
}