File size: 4,126 Bytes
6966756 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | <?php
namespace App\Models;
use App\Constants\Status;
use App\Traits\UserNotify;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, UserNotify;
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'ver_code',
'balance',
'kyc_data'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
'kyc_data' => 'object',
'ver_code_send_at' => 'datetime'
];
public function prompts()
{
return $this->hasMany(Prompt::class, 'user_id')->where('status', Status::PROMPT_APPROVED);
}
public function sales()
{
return $this->hasManyThrough(OrderDetails::class, Prompt::class, 'user_id', 'prompt_id', 'id', 'id')
->join('orders', 'order_details.order_id', '=', 'orders.id')
->select('order_details.*', 'orders.*')
->with('prompt');
}
public function sells()
{
return $this->hasManyThrough(OrderDetails::class, Order::class, 'user_id', 'order_id', 'id', 'id')
->where('orders.status', Status::ORDER_COMPLETED);
}
public function purchases()
{
return $this->hasManyThrough(OrderDetails::class, Order::class, 'user_id', 'order_id', 'id', 'id')
->where('orders.status', Status::ORDER_COMPLETED);
}
public function loginLogs()
{
return $this->hasMany(UserLogin::class);
}
public function transactions()
{
return $this->hasMany(Transaction::class)->orderBy('id', 'desc');
}
public function deposits()
{
return $this->hasMany(Deposit::class)->where('status', '!=', Status::PAYMENT_INITIATE);
}
public function withdrawals()
{
return $this->hasMany(Withdrawal::class)->where('status', '!=', Status::PAYMENT_INITIATE);
}
public function tickets()
{
return $this->hasMany(SupportTicket::class);
}
public function fullname(): Attribute
{
return new Attribute(
get: fn() => $this->firstname . ' ' . $this->lastname,
);
}
public function mobileNumber(): Attribute
{
return new Attribute(
get: fn() => $this->dial_code . $this->mobile,
);
}
public function follows()
{
return $this->hasMany(Follow::class, 'user_id');
}
public function followers()
{
return $this->hasMany(Follow::class, 'followed_user_id');
}
public function isFollowing($userId)
{
return $this->follows()->where('followed_user_id', $userId)->exists();
}
// SCOPES
public function scopeActive($query)
{
return $query->where('status', Status::USER_ACTIVE)->where('ev', Status::VERIFIED)->where('sv', Status::VERIFIED);
}
public function scopeBanned($query)
{
return $query->where('status', Status::USER_BAN);
}
public function scopeEmailUnverified($query)
{
return $query->where('ev', Status::UNVERIFIED);
}
public function scopeMobileUnverified($query)
{
return $query->where('sv', Status::UNVERIFIED);
}
public function scopeKycUnverified($query)
{
return $query->where('kv', Status::KYC_UNVERIFIED);
}
public function scopeKycPending($query)
{
return $query->where('kv', Status::KYC_PENDING);
}
public function scopeEmailVerified($query)
{
return $query->where('ev', Status::VERIFIED);
}
public function scopeMobileVerified($query)
{
return $query->where('sv', Status::VERIFIED);
}
public function scopeWithBalance($query)
{
return $query->where('balance', '>', 0);
}
public function deviceTokens()
{
return $this->hasMany(DeviceToken::class);
}
}
|