Expand Link app with analytics, settings, and custom domains.
Deploy Ladill Link / deploy (push) Successful in 37s
Deploy Ladill Link / deploy (push) Successful in 37s
Add Bitly-style branded domain support via Ladill Domains SSL API, account analytics dashboard, settings page with default domain picker, and fix SSO/dashboard issues from QR Plus template leftovers. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Customer-branded short-link domain (e.g. go.brand.com) for Ladill Link.
|
||||
*/
|
||||
class LinkCustomDomain extends Model
|
||||
{
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
|
||||
public const STATUS_FAILED = 'failed';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'host', 'include_www', 'is_default', 'status', 'ssl_status',
|
||||
'dns_verified_at', 'ssl_issued_at', 'ssl_expires_at', 'last_error',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'include_www' => 'boolean',
|
||||
'is_default' => 'boolean',
|
||||
'dns_verified_at' => 'datetime',
|
||||
'ssl_issued_at' => 'datetime',
|
||||
'ssl_expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function isLive(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_ACTIVE && $this->ssl_status === self::STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
public function baseUrl(): string
|
||||
{
|
||||
return 'https://'.$this->host;
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (LinkCustomDomain $domain) {
|
||||
$domain->host = strtolower(trim((string) $domain->host, " \t\n\r\0\x0B./"));
|
||||
$domain->host = preg_replace('/^www\./', '', $domain->host) ?: $domain->host;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,12 @@ class ShortLink extends Model
|
||||
return $this->hasMany(LinkClick::class);
|
||||
}
|
||||
|
||||
public function publicUrl(): string
|
||||
public function publicUrl(?User $owner = null): string
|
||||
{
|
||||
return self::publicBaseUrl().'/'.$this->slug;
|
||||
$owner ??= $this->user;
|
||||
$base = $owner ? $owner->publicLinkBaseUrl() : self::publicBaseUrl();
|
||||
|
||||
return rtrim($base, '/').'/'.$this->slug;
|
||||
}
|
||||
|
||||
public static function publicBaseUrl(): string
|
||||
|
||||
@@ -8,6 +8,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,17 @@ class User extends Authenticatable
|
||||
return ['email_verified_at' => 'datetime', 'password' => 'hashed'];
|
||||
}
|
||||
|
||||
public function canAccessAccount(int $accountId): bool
|
||||
{
|
||||
return $accountId === $this->id;
|
||||
}
|
||||
|
||||
/** @return Collection<int, User> */
|
||||
public function accessibleAccounts(): Collection
|
||||
{
|
||||
return collect([$this]);
|
||||
}
|
||||
|
||||
public function linkWallet(): HasOne
|
||||
{
|
||||
return $this->hasOne(LinkWallet::class);
|
||||
@@ -37,6 +49,25 @@ class User extends Authenticatable
|
||||
return $this->hasMany(ShortLink::class);
|
||||
}
|
||||
|
||||
public function linkCustomDomains(): HasMany
|
||||
{
|
||||
return $this->hasMany(LinkCustomDomain::class);
|
||||
}
|
||||
|
||||
public function defaultLinkDomain(): ?LinkCustomDomain
|
||||
{
|
||||
return $this->linkCustomDomains()
|
||||
->where('is_default', true)
|
||||
->where('status', LinkCustomDomain::STATUS_ACTIVE)
|
||||
->where('ssl_status', LinkCustomDomain::STATUS_ACTIVE)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function publicLinkBaseUrl(): string
|
||||
{
|
||||
return $this->defaultLinkDomain()?->baseUrl() ?? ShortLink::publicBaseUrl();
|
||||
}
|
||||
|
||||
public function getOrCreateLinkWallet(): LinkWallet
|
||||
{
|
||||
return $this->linkWallet()->firstOrCreate(
|
||||
|
||||
Reference in New Issue
Block a user