*/ protected $fillable = [ 'first_name', 'last_name', 'email', 'phone_number', 'verified', 'password', 'options', ]; /** * 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', ]; /** * Get fullname of user * * @return string */ public function fullname(): Attribute { return Attribute::make( get: fn () => sprintf('%s %s', $this->first_name, $this->last_name) ); } /** * Get users locale */ public function locale(): Attribute { return Attribute::make( get: fn () => $this->options->get('locale'), ); } /** * Get all role names * * @return string */ public function roleNames(): Attribute { return Attribute::make( get: fn () => $this->getRoleNames()->implode(', ') ); } /** * Addresses */ public function addresses(): HasMany { return $this->hasMany(UserAddress::class); } /** * User's carts */ public function carts(): HasMany { return $this->hasMany(CartItem::class); } /** * User's favorite products */ public function favorites(): HasMany { return $this->hasMany(Favorite::class); } /** * User's viewed products */ public function productViews(): HasMany { return $this->hasMany(ProductView::class); } /** * User's favorite products */ public function reviews(): HasMany { return $this->hasMany(Review::class); } /** * Orders */ public function orders(): HasMany { return $this->hasMany(Order::class); } /** * Documents */ public function documents(): HasOne { return $this->hasOne(UserDoc::class); } /** * Get Company name */ public function companyName(): ?string { $this->loadMissing('documents'); return $this->documents?->formattedCorparationName; } /** * User owns product */ public function ownsProduct($product): bool { return true; // return CacheRepository::make(); } /** * Owns inventory */ public function ownsInventory($inventory): bool { return $this->channel()->id === $inventory->channel_id; } /** * Check if user does not own any inventories */ public function doesntOwnInventory(): bool { return $this->inventoryCount() === 0; } /** * Inventory count */ public function inventoryCount(): int { $inventoryCount = cache()->store('array')->get('user_inventory_count'); if (! $inventoryCount) { cache()->store('array')->put('user_inventory_count', $this->channel()->inventories()->count()); } return cache()->store('array')->get('user_inventory_count'); } }