file($placeholderPath); } abort(404); } // Determine content type $extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); $contentType = match ($extension) { 'jpg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', default => 'image/jpeg', }; // Serve the file with proper headers return response()->file($filePath, [ 'Content-Type' => $contentType, 'Cache-Control' => 'public, max-age=31536000', // Cache for 1 year ]); } }