You can replace the TransformationResult model with your own to add scopes, methods, or extra columns. Extend the package's model:
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Spatie\LaravelUrlAiTransformer\Models\TransformationResult as BaseTransformationResult;
class TransformationResult extends BaseTransformationResult
{
public function scopeSuccessful(Builder $query): Builder
{
return $query->whereNotNull('successfully_completed_at');
}
public function scopeFailed(Builder $query): Builder
{
return $query->whereNotNull('latest_exception_seen_at');
}
public function isStale(): bool
{
return $this->successfully_completed_at?->isBefore(now()->subDays(7)) ?? true;
}
}
Register it in the config file:
'model' => App\Models\TransformationResult::class,
The package will now use your model everywhere: when storing results, and when you retrieve them through forUrl() and findForUrl().
If your model needs extra columns, add them with a migration in your application. A transformer can fill them by overriding resultFrom(). See Customizing the stored result.