*/ protected $fillable = [ 'username', 'name', 'email', 'phone', 'email_verified_at', 'phone_verified_at', 'password', 'locale', 'active', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; /** * Branches associated with user */ public function branches(): BelongsToMany { return $this->belongsToMany(Branch::class); } /** * Loan orders user created */ public function loanOrders(): HasMany { return $this->hasMany(LoanOrder::class); } /** * Card orders user created */ public function cardOrders(): HasMany { return $this->hasMany(CardOrder::class); } /** * Check if user has role. */ public function withoutRole(): bool { return $this->roles->count() === 0; } /** * Check if user can access api docs */ public function canAccessApiDocs(): bool { return $this->isMe() || in_array($this->username, [ 'muhammet', ]); } /** * Check if user is me. */ public function isMe(): bool { return $this->email === 'nurmuhammet@mail.com'; } /** * Check if user is super admin. */ public function isSuperAdmin(): bool { if ($this->isMe()) { return true; } return $this->hasRole('superadmin'); } /** * Check if user is admin. */ public function isAdmin(): bool { if ($this->isMe()) { return true; } return $this->hasRole(['king', 'superadmin', 'admin']); } /** * Check if user is operator. */ public function isOperator(): bool { return $this->hasRole('operator'); } /** * Is System User */ public function isSystemUser(): bool { return $this->isAdmin() || $this->isOperator(); } /** * Check if user owns loan order. */ public function ownsLoanOrder(LoanOrder $loanOrder): bool { return $this->id === intval($loanOrder->user_id); } /** * Check if user owns loan order. */ public function ownsCardOrder(CardOrder $cardOrder): bool { return $this->id === intval($cardOrder->user_id); } /** * Check if phone is verified */ public function phoneIsVerified(): bool { return ! is_null($this->phone_verified_at); } /** * Profile page of user */ public function profilePage(): string { return sprintf('/resources/users/%s', $this->id); } }