Files
ladill-link/app/Models/ShortLink.php
T
isaaccladandCursor 5982165128
Deploy Ladill Link / deploy (push) Successful in 31s
Fix ladl.link 404s for QR ecosystem slugs.
Only direct Link redirects use destination_url; catalog QR slugs proxy through the platform resolver instead of malformed summary URLs.

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

88 lines
2.2 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();
}
/** Simple URL redirects created in Link; QR ecosystem slugs resolve via the platform proxy. */
public function isDirectRedirect(): bool
{
return $this->is_managed_here && $this->source_kind === 'redirect';
}
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),
};
}
}