Add Ladill Link URL shortener on ladl.link.

Management UI at link.ladill.com with GHS 0.05 per link wallet billing,
click analytics, and legacy fallback to ladill.com/q for QR ecosystem codes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-27 10:58:41 +00:00
co-authored by Cursor
parent 04e4f6ab51
commit d9c91ad7d8
30 changed files with 1002 additions and 247 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class LinkClick extends Model
{
protected $fillable = [
'short_link_id',
'ip_hash',
'user_agent',
'referer',
'country',
'is_unique',
'clicked_at',
];
protected $casts = [
'is_unique' => 'boolean',
'clicked_at' => 'datetime',
];
public function shortLink(): BelongsTo
{
return $this->belongsTo(ShortLink::class);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class LinkTransaction extends Model
{
public const TYPE_DEBIT = 'debit';
protected $fillable = [
'user_id',
'link_wallet_id',
'short_link_id',
'type',
'amount_ghs',
'balance_after_ghs',
'reference',
'status',
'description',
'metadata',
];
protected $casts = [
'amount_ghs' => 'decimal:4',
'balance_after_ghs' => 'decimal:4',
'metadata' => 'array',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function wallet(): BelongsTo
{
return $this->belongsTo(LinkWallet::class, 'link_wallet_id');
}
public function shortLink(): BelongsTo
{
return $this->belongsTo(ShortLink::class);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class LinkWallet extends Model
{
public const STATUS_ACTIVE = 'active';
protected $fillable = [
'user_id',
'links_total',
'clicks_total',
'status',
];
protected $casts = [
'links_total' => 'integer',
'clicks_total' => 'integer',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function transactions(): HasMany
{
return $this->hasMany(LinkTransaction::class);
}
public static function pricePerLink(): float
{
return (float) config('link.price_per_link_ghs', 0.05);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?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',
'slug',
'label',
'destination_url',
'is_active',
'clicks_total',
'unique_clicks_total',
'last_clicked_at',
'expires_at',
];
protected $casts = [
'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(): string
{
return self::publicBaseUrl().'/'.$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();
}
}
+7 -38
View File
@@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Sanctum\HasApiTokens;
/**
@@ -28,51 +27,21 @@ class User extends Authenticatable
return ['email_verified_at' => 'datetime', 'password' => 'hashed'];
}
public function memberships(): HasMany
public function linkWallet(): HasOne
{
return $this->hasMany(QrTeamMember::class, 'user_id')
->where('status', QrTeamMember::STATUS_ACTIVE);
return $this->hasOne(LinkWallet::class);
}
public function canAccessAccount(int $accountId): bool
public function shortLinks(): HasMany
{
return $accountId === $this->id
|| $this->memberships()->where('account_id', $accountId)->exists();
return $this->hasMany(ShortLink::class);
}
/** @return Collection<int, User> */
public function accessibleAccounts(): Collection
public function getOrCreateLinkWallet(): LinkWallet
{
$ids = $this->memberships()->pluck('account_id')->all();
return collect([$this])->merge(self::whereIn('id', $ids)->get())->unique('id')->values();
}
public function qrWallet(): HasOne
{
return $this->hasOne(QrWallet::class);
}
public function qrCodes(): HasMany
{
return $this->hasMany(QrCode::class);
}
public function qrSetting(): HasOne
{
return $this->hasOne(QrSetting::class);
}
public function getOrCreateQrSetting(): QrSetting
{
return $this->qrSetting()->firstOrCreate([]);
}
public function getOrCreateQrWallet(): QrWallet
{
return $this->qrWallet()->firstOrCreate(
return $this->linkWallet()->firstOrCreate(
[],
['credit_balance' => 0, 'qr_codes_total' => 0, 'scans_total' => 0, 'status' => QrWallet::STATUS_ACTIVE],
['links_total' => 0, 'clicks_total' => 0, 'status' => LinkWallet::STATUS_ACTIVE],
);
}