Files
ladill-link/app/Models/ShortLink.php
T
isaaccladandCursor f1fe749934
Deploy Ladill Link / deploy (push) Successful in 29s
Aggregate ladl.link slugs from all platform apps in the link list.
Sync QR and storefront short codes from sibling apps via a platform catalog API so My Links shows every ladl.link URL in one place.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 13:26:16 +00:00

82 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ShortLink extends Model
{
protected $fillable = [
'user_id',
'source_app',
'source_kind',
'source_ref',
'slug',
'label',
'destination_url',
'manage_url',
'is_managed_here',
'is_active',
'clicks_total',
'unique_clicks_total',
'last_clicked_at',
'expires_at',
];
protected $casts = [
'is_managed_here' => 'boolean',
'is_active' => 'boolean',
'clicks_total' => 'integer',
'unique_clicks_total' => 'integer',
'last_clicked_at' => 'datetime',
'expires_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function clicks(): HasMany
{
return $this->hasMany(LinkClick::class);
}
public function publicUrl(?User $owner = null): string
{
$owner ??= $this->user;
$base = $owner ? $owner->publicLinkBaseUrl() : self::publicBaseUrl();
return rtrim($base, '/').'/'.$this->slug;
}
public static function publicBaseUrl(): string
{
$domain = (string) config('link.public_domain', 'ladl.link');
return 'https://'.$domain;
}
public function isExpired(): bool
{
return $this->expires_at !== null && $this->expires_at->isPast();
}
public function sourceAppLabel(): string
{
return match ($this->source_app) {
'link' => 'Ladill Link',
'qrplus' => 'QR Plus',
'merchant' => 'Merchant',
'events' => 'Events',
'mini' => 'Mini',
'give' => 'Give',
'transfer' => 'Transfer',
'platform' => 'Ladill',
default => ucfirst((string) $this->source_app),
};
}
}