// FOUND IN: app/Models/User.php - Missing soft delete handling protected static function booted() { static::deleting(function ($user) { if ($user->isForceDeleting()) { // Force delete related records $user->wallet()->forceDelete(); $user->apiKeys()->forceDelete(); } else { // Soft delete - just log it Log::info('User soft deleted: ' . $user->id); } }); } namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use App\Traits\HasWallet; use App\Traits\HasReferral; use App\Traits\Loggable; class User extends Authenticatable implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable, SoftDeletes, HasWallet, HasReferral, Loggable; protected $fillable = [ 'username', 'email', 'password', 'first_name', 'last_name', 'phone', 'country', 'city', 'address', 'status', 'email_verified_at', 'phone_verified_at', 'two_factor_enabled', 'two_factor_secret', 'last_login_at', 'last_login_ip', 'referral_code', 'referred_by', ]; protected $hidden = [ 'password', 'remember_token', 'two_factor_secret', ]; protected $casts = [ 'email_verified_at' => 'datetime', 'phone_verified_at' => 'datetime', 'last_login_at' => 'datetime', 'two_factor_enabled' => 'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; protected $appends = [ 'full_name', 'avatar', 'is_verified', 'account_status', ]; // Relationships public function wallet() { return $this->hasOne(Wallet::class); } public function transactions() { return $this->hasMany(Transaction::class); } public function orders() { return $this->hasMany(Order::class); } public function tickets() { return $this->hasMany(Ticket::class); } public function loginLogs() { return $this->hasMany(LoginLog::class); } public function sessions() { return $this->hasMany(UserSession::class); } public function notifications() { return $this->morphMany(Notification::class, 'notifiable'); } public function activityLogs() { return $this->morphMany(ActivityLog::class, 'causer'); } public function referrals() { return $this->hasMany(Referral::class, 'referrer_id'); } public function referredBy() { return $this->belongsTo(User::class, 'referred_by'); } public function referralCommissions() { return $this->hasMany(ReferralCommission::class, 'referrer_id'); } public function apiKeys() { return $this->hasMany(UserApiKey::class); } // Accessors public function getFullNameAttribute() { return trim($this->first_name . ' ' . $this->last_name) ?: $this->username; } public function getAvatarAttribute() { return 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) . '?s=200&d=mp'; } public function getIsVerifiedAttribute() { return !is_null($this->email_verified_at); } public function getAccountStatusAttribute() { return ucfirst($this->status); } public function getInitialsAttribute() { if ($this->first_name && $this->last_name) { return strtoupper(substr($this->first_name, 0, 1) . substr($this->last_name, 0, 1)); } return strtoupper(substr($this->username, 0, 2)); } public function getReferralLinkAttribute() { return route('register', ['ref' => $this->referral_code]); } // Scopes public function scopeActive($query) { return $query->where('status', 'active'); } public function scopeSuspended($query) { return $query->where('status', 'suspended'); } public function scopeBanned($query) { return $query->where('status', 'banned'); } public function scopeVerified($query) { return $query->whereNotNull('email_verified_at'); } public function scopeOnline($query) { return $query->where('last_login_at', '>=', now()->subMinutes(5)); } // Methods public function isActive() { return $this->status === 'active'; } public function isSuspended() { return $this->status === 'suspended'; } public function isBanned() { return $this->status === 'banned'; } public function updateLastLogin($ip) { $this->update([ 'last_login_at' => now(), 'last_login_ip' => $ip, ]); } public function generateReferralCode() { $this->referral_code = strtoupper(substr(md5($this->id . time()), 0, 8)); $this->save(); return $this->referral_code; } public function hasVerifiedPhone() { return !is_null($this->phone_verified_at); } public function markPhoneAsVerified() { return $this->forceFill([ 'phone_verified_at' => $this->freshTimestamp(), ])->save(); } public function routeNotificationForMail($notification) { return $this->email; } public function routeNotificationForNexmo($notification) { return $this->phone; } public function routeNotificationForTwilio($notification) { return $this->phone; } }