'int', 'calories' => 'float', 'carbohydrates' => 'float', 'cholesterol' => 'float', 'fat' => 'float', 'protein' => 'float', 'sodium' => 'float', ]; /** * @inheritdoc */ protected $appends = [ 'days_formatted', ]; /** * Get the days for the goals as strings in array keyed by dow. */ public function getDaysFormattedAttribute(): Collection { if (empty($this->days)) { return new Collection([]); } return self::days()->filter(function ($day) { if (($this->days & $day['value']) != 0) { return true; } return false; }); } /** * Get all supported days and metadata. * * Each entry has the following keys: * - value: Day value (used for bitwise operations). * - label: Human-readable name for the day. * - dow: ISO-8601 numeric representation of the day of the week. */ public static function days(): Collection { return new Collection([ [ 'value' => 1, 'label' => 'monday', 'dow' => 1, ], [ 'value' => 2, 'label' => 'tuesday', 'dow' => 2, ], [ 'value' => 4, 'label' => 'wednesday', 'dow' => 3, ], [ 'value' => 8, 'label' => 'thursday', 'dow' => 4, ], [ 'value' => 16, 'label' => 'friday', 'dow' => 5, ], [ 'value' => 32, 'label' => 'saturday', 'dow' => 6, ], [ 'value' => 64, 'label' => 'sunday', 'dow' => 7, ], ]); } /** * Get the User this goal belongs to. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } }