---
name: zeus-helen
description: Use when installing, configuring, or integrating lara-zeus/helen short URLs, visit tracking, QR code generation, ShortUrlAction, or linkable Eloquent models.
---

# Lara Zeus Helen (`lara-zeus/helen`)

## Overview & Requirements
`lara-zeus/helen` is a paid Filament short URL management and QR code generator plugin with visit tracking (device, browser, platform, country, IP, referrer).
- **PHP**: `^8.1`
- **Dependencies**: `jenssegers/agent` (`^2.6`), `lara-zeus/filament-plugin-tools` (`^3.0`), `lara-zeus/qr` (`^3.0`)

## Installation
Configure the Lara Zeus private Satis repository and license credentials in `auth.json` (from your `https://larazeus.com/dashboard` account):
```bash
composer config repositories.larazeus composer https://larazeus.com/satis
composer require lara-zeus/helen
php artisan vendor:publish --tag=zeus-helen-migrations
php artisan migrate
```

## Configuration & Migrations
Published migrations: `create_links_table`, `create_visits_table`, `add_model_morphs_to_links_table`.
Publish the config file if you want to customize `prefix` or default models:
```bash
php artisan vendor:publish --tag=zeus-helen-config
```
Options in `config/zeus-helen.php`:
- `prefix`: `'short/'` (used in `routes/web.php` redirect route `/{prefix}/{id}`)
- `models`: `'Link' => Link::class`, `'Visit' => Visit::class`

## Filament Panel Registration
Register `HelenPlugin` in your `PanelProvider`:
```php
use LaraZeus\Helen\Filament\Resources\LinksResource;
use LaraZeus\Helen\HelenPlugin;

->plugins([
    HelenPlugin::make()
        ->baseDomain('site.test')
        ->prefix('link/')
        ->keyLength(4)
        ->models([
            'Link' => \LaraZeus\Helen\Models\Link::class,
            'Visit' => \LaraZeus\Helen\Models\Visit::class,
        ])
        ->globallySearchableAttributes([
            LinksResource::class => ['url', 'short_key'],
        ])
        ->navigationGroupLabel('Helen'),
])
```

## Core Usage & Examples

### 1. Short URL + QR Action on Any Record
Use `ShortUrlAction` in Filament tables or pages to generate a short link and configure its QR code for a record:
```php
use LaraZeus\Helen\Actions\ShortUrlAction;

ShortUrlAction::make('short-link')
    ->distUrl(fn ($record): string => route('posts.show', $record));
```
When saved, `ShortUrlAction` automatically attaches `linkable_type` and `linkable_id` to the `Link` record.

### 2. Linkable Models (`ShortLinks` trait)
Add `LaraZeus\Helen\Models\Concerns\ShortLinks` to morph-linked models to customize table labels and titles:
```php
use Illuminate\Database\Eloquent\Model;
use LaraZeus\Helen\Models\Concerns\ShortLinks;

class Post extends Model
{
    use ShortLinks;

    public static function getLabelKey(): string
    {
        return 'title';
    }

    public static function getTitle(): string
    {
        return 'Posts';
    }
}
```

## Common Pitfalls
- **Calling `->helenModels(...)`**: `HelenPlugin` uses `HasModels`, so the method is `->models([...])`, not `->helenModels([...])`.
- **Missing `->distUrl(...)` on `ShortUrlAction`**: `ShortUrlAction` evaluates `$this->distUrl` to look up or create the `Link` model; omitting it triggers an uninitialized property error.
- **`prefix` mismatch**: `routes/web.php` reads `config('zeus-helen.prefix')`, while `Helen::linkBuilder()` reads `HelenPlugin::get()->getPrefix()`; keep both aligned when customizing prefixes.
