Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Url Ai Transformer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

title: Getting started weight: 1

Let's build a simple example that transforms blog posts into structured data. We'll use the LdJsonTransformer that comes with the package to extract structured information from web pages.

First, you should use the Transform class to register URLs to transform, and which transformer to use:

use Spatie\LaravelUrlAiTransformer\Support\Transform;
use Spatie\LaravelUrlAiTransformer\Transformers\LdJsonTransformer;

// typically, in a service provider
Transform::urls(
    'https://spatie.be/blog',
    'https://spatie.be/open-source',
    'https://spatie.be/about-us'
)->usingTransformers(new LdJsonTransformer)

Running transformations

Now, you can transform the URLs by running:

php artisan transform-urls

This command will dispatch a queued job for each URL. Inside that queued job:

  • the content of the URL will be fetched.
  • the content will be sent to the configured AI.
  • the response from the AI will be stored in the transformation_results table.

What's in the database?

The transformation_results table stores all transformation data with the following fields:

  • url: The URL that was transformed
  • type: The transformer type (e.g., 'ldJson', 'image')
  • result: The AI-generated content stored as text
  • successfully_completed_at: Timestamp when the transformation completed successfully
  • latest_exception_seen_at: Timestamp of the most recent error (if any)
  • latest_exception_message: The error message from the last failed attempt
  • latest_exception_trace: Stack trace for debugging failed transformations
  • created_at: When the record was first created
  • updated_at: When the record was last modified

The latest_exception fields will be cleared when the transformation completes successfully.

Retrieving transformation results

Here's how you can retrieve transformation results in your application.

use Spatie\LaravelUrlAiTransformer\Models\TransformationResult;

// Get structured data for a specific URL
$ldJsonData = TransformationResult::forUrl('https://spatie.be/blog', 'ldJson');

The first parameter is the URL, the second parameter is the transformer type. By default, transformer type is the lowercased class name of the transformer without the Transformer suffix.

Scheduling transformations

To keep your transformations up to date, schedule the command to run periodically:

// In app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
    $schedule->command('transform-urls')
        ->daily()
        ->at('02:00');
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport