spatie/laravel-url-ai-transformer
Laravel package to transform URLs and their web content with AI. Extract structured data (JSON-LD), generate summaries, images, or custom outputs via transformers and prompts. Runs via an Artisan command and stores results in the database for later retrieval.
laravel-ai (recommended but not mandatory).UrlTransformer or implement UrlTransformerContract for domain-specific logic.UrlTransforming, UrlTransformFailed).graph LR
A[URL Input] --> B[Fetch Content]
B --> C[AI Transformer]
C --> D[Cache/Store]
D --> E[Output: Transformed Data]
| Risk Area | Mitigation Strategy |
|---|---|
| AI Provider Costs | Implement rate-limiting and fallback mechanisms (e.g., cached responses). |
| External API Latency | Use Laravel queues (e.g., transform-url:delayed) and retries (via spatie/laravel-queue-retries). |
| Content Scraping | Validate URLs with spatie/url package to avoid malformed inputs. |
| Vendor Lock-in | Abstract AI calls behind a strategy pattern (e.g., AiServiceInterface). |
| Caching Complexity | Leverage Laravel’s cache tags or Redis for invalidation. |
spatie/laravel-mock-ai)?config/app.php (1-line addition).php artisan vendor:publish --tag="url-ai-transformer-config") for API keys/transformer settings.UrlTransformer::transform() with dispatch() for async processing..env (e.g., OPENAI_API_KEY).AiServiceInterface and bind to the container.cache()->remember()) for transformed results.transformed_at, ai_model_used) in a url_transformations table.UrlTransformer::transform('https://example.com')).JobSubmitted event to transform job description URLs.UrlTransformFailed events in Sentry).| Component | Compatibility Notes |
|---|---|
| Laravel Version | Tested on Laravel 9/10. May require minor tweaks for Laravel 11 (new features). |
| PHP Version | PHP 8.1+ (uses named arguments, attributes). |
| AI Providers | OpenAI v1 API by default. Anthropic requires spatie/laravel-ai. |
| Database | No strict requirements, but MySQL/PostgreSQL recommended for metadata storage. |
| Caching | Works with Redis, Memcached, or Laravel’s file cache. |
spatie/laravel-ai is installed if using OpenAI/Anthropic (or implement AiServiceInterface).php artisan queue:work) for async processing.UrlTransformer (e.g., services/UrlAiService.php).ExtractProductSpecsTransformer).https://staging.example.com).phpunit before deploying.text-davinci-03 → gpt-4).spatie/laravel-config-array).spatie/laravel-queue-retries).spatie/url package.UrlTransforming events with:
event(new UrlTransforming($url, $transformer));
queue:work --sleep=3 --tries=3 to avoid overload.url_transformations inserts (e.g., use DB::transaction()).gpt-3.5-turbo instead of gpt-4) for non-critical paths.How can I help you explore Laravel packages today?