- How do I install spatie/visit for Laravel projects?
- Run `composer global require spatie/visit` to install globally. For Laravel-specific usage, install via `composer require spatie/visit` in your project. Ensure you have `bat` (for HTML) and `jq` (for JSON) installed for colorized output.
- Can I use spatie/visit to scrape dynamic JavaScript-rendered content?
- No, spatie/visit fetches static HTML/JSON. For dynamic content, pair it with `spatie/laravel-headless-chrome` or use Playwright/Puppeteer. Example: `$visit->withHeadlessBrowser()->html()`.
- What Laravel versions does spatie/visit support?
- Officially tested on Laravel 10/11 (PHP 8.1+). Laravel 9 may work but isn’t guaranteed. Check the [GitHub issues](https://github.com/spatie/visit/issues) for version-specific fixes.
- How do I customize HTTP headers or timeouts in Laravel?
- Configure via `config/visit.php`. Example: `'timeout' => 30, 'headers' => ['User-Agent' => 'MyApp/1.0']`. Override defaults in your `AppServiceProvider` using `Visit::configure()`.
- Is spatie/visit thread-safe for concurrent requests?
- Yes, it’s stateless and designed for concurrent use. For high-volume scraping, queue requests with Laravel Queues (`Visit::queue()`) to avoid rate limits or timeouts.
- How do I mock spatie/visit for unit tests?
- Use Laravel’s HTTP client mocking. Example: `Visit::shouldReceive('url')->andReturn(new VisitResponse($html, 200));`. The package’s Guzzle-based client is easily replaceable.
- What’s the difference between `visit` CLI and the Laravel package?
- The CLI (`visit <url>`) is a standalone tool. The Laravel package adds integration with Laravel’s HTTP client, config system, and service container for programmatic use (e.g., `Visit::url('...')->html()`).
- How do I handle redirects with spatie/visit?
- By default, it follows redirects. Disable with `--no-follow` or configure globally in `config/visit.php` with `'follow_redirects' => false`. Track redirects via `$visit->getRedirects()`.
- Can I use spatie/visit in Laravel queues for async processing?
- Yes. Dispatch a job with `Visit::queue('https://example.com')`. Use `spatie/queueable-middleware` for retries or `Laravel Horizon` to monitor long-running visits.
- What are the alternatives to spatie/visit for Laravel?
- For static content: Laravel’s built-in `Http::get()` or Guzzle middleware. For dynamic content: Playwright/Puppeteer. For full scraping: Symfony Panther. spatie/visit excels for quick, human-readable CLI/terminal use.