*/ protected $fillable = [ 'id', 'category_id', 'old_price', 'price', 'pricing', 'quantity', 'image', 'description', 'other', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'pricing' => ShopItemPricingEnum::class, ]; /** * @return bool */ public function userCanBuy(): bool { $user = Auth::user(); if ($this->pricing == ShopItemPricingEnum::CASH) return $user->cash >= $this->price; elseif ($this->pricing == ShopItemPricingEnum::MILEAGE) return $user->mileage >= $this->price; return false; } }