*/ protected function casts(): array { return [ 'is_active' => 'boolean', 'clicks_count' => 'integer', 'registrations_count' => 'integer', 'orders_count' => 'integer', 'deleted_at' => 'datetime', ]; } /** * @return BelongsTo */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'user_affiliates', 'affiliate_id', 'user_id') ->withPivot('clicked_at', 'registered_at') ->withTimestamps(); } /** * Generate the affiliate tracking link * * @return string */ public function getTrackingLinkAttribute(): string { $baseUrl = config('app.url'); return $baseUrl . '/signup?tracking=' . $this->code; } }