'float', 'carbohydrates' => 'float', 'cholesterol' => 'float', 'fat' => 'float', 'protein' => 'float', 'serving_size' => 'float', 'serving_weight' => 'float', 'sodium' => 'float', ]; /** * @inheritdoc */ protected $appends = ['serving_size_formatted']; /** * Get the serving size as a fractional. */ public function getServingSizeFormattedAttribute(): string { return Number::fractionStringFromFloat($this->serving_size); } /** * Get the food amounts using this food. */ public function foodAmounts(): HasMany { return $this->hasMany(FoodAmount::class); } /** * Gets search results for a term. */ public static function search(string $term, int $limit = 10): Collection { return (new static)::where('name', 'like', "%{$term}%")->limit($limit)->get(); } }