Getting started | laravel-url-ai-transformer | Spatie

 SPATIE

  Laravel URL AI Transformer
=============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-url-ai-transformer](https://spatie.be/docs/laravel-url-ai-transformer/v1)  Basic-usage  Getting started

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-url-ai-transformer/v1)

  Getting started
- [ Introduction ](https://spatie.be/docs/laravel-url-ai-transformer/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-url-ai-transformer/v1/support-us)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-url-ai-transformer/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-url-ai-transformer/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-url-ai-transformer/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-url-ai-transformer/v1/about-us)

Basic usage
-----------

- [ Getting started ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/getting-started)
- [ Registering transformations ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/registering-transformations)
- [ Writing your own transformers ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/writing-your-own-transformers)

Advanced usage
--------------

- [ Testing transformers ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/testing-transformers)
- [ Conditional transformations ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/conditional-transformations)
- [ Crawling URLs ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/crawling-urls)
- [ Customizing AI models ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/customizing-ai-models)
- [ Exploring command options ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/exploring-command-options)
- [ Overriding actions ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/overriding-actions)
- [ Regenerating results ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/regenerating-results)

 Getting started
===============

###  On this page

1. [ Running transformations ](#content-running-transformations)
2. [ What's in the database? ](#content-whats-in-the-database)
3. [ Retrieving transformation results ](#content-retrieving-transformation-results)
4. [ Scheduling transformations ](#content-scheduling-transformations)

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');
}
```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
