- How do I install torchlight/torchlight-laravel in my Laravel project?
- Run `composer require torchlight/torchlight-laravel` to install the package. Then publish the config file with `php artisan torchlight:install`, which creates `config/torchlight.php` with default settings like API token, theme, and cache driver.
- Does this package work with Laravel 10 or 11?
- Yes, the package supports Laravel 8.0–13.x, including Laravel 10 and 11. It’s tested against the latest Laravel versions and integrates with Blade components, Livewire, and Inertia.js seamlessly.
- Can I use custom VS Code themes with this package?
- Absolutely. Torchlight supports every VS Code theme, including custom ones. Set your preferred theme in `config/torchlight.php` under the `theme` key, or use an environment variable like `TORCHLIGHT_THEME=your-theme-name`.
- What happens if the Torchlight API is down or rate-limited?
- The package includes fallback mechanisms. For production, implement a local cache (e.g., Redis) with short TTLs or use a static HTML backup. You can also throttle requests or self-host Torchlight if uptime is critical.
- How do I highlight code in Blade templates? Is there a directive or component?
- Enable Blade components by setting `'blade_components' => true` in `config/torchlight.php`. Then use the `@torchlight` directive or the `torchlight` component in your Blade files, e.g., `<x-torchlight>code here</x-torchlight>`.
- Does this package support line highlighting or git diffs?
- Yes, Torchlight supports advanced features like line highlighting and git diffs out of the box. Pass options like `highlightLines` or `diff` directly to the API call via the `torchlight()` helper or Block objects.
- Can I cache highlighted code blocks for better performance?
- Yes, the package integrates with Laravel’s cache drivers (file, Redis, database, etc.). Configure the `cache` key in `config/torchlight.php` to use your preferred driver, and Torchlight will automatically cache rendered blocks.
- Is there a way to test this package in my CI pipeline?
- The package includes mockable facades for testing. Use `Torchlight::shouldReceive()` to stub API calls in PHPUnit tests. Example: `Torchlight::shouldReceive('highlight')->andReturn('<div>mocked</div>');` for unit tests.
- How do I handle dynamic code blocks that change frequently?
- For dynamic content, use short cache TTLs or disable caching entirely by setting `'cache' => null`. Alternatively, manually invalidate cache entries via `Cache::forget()` when content updates, especially in multi-user environments.
- What are the alternatives if I don’t want to use an external API?
- If API dependency is a concern, consider client-side highlighters like Prism.js or Highlight.js for static content. For self-hosted solutions, explore PHP libraries like Rouge (used by Pygments) or build a custom syntax highlighter with Laravel’s service container.