fix exam get begin and end

This commit is contained in:
xiaomlove
2024-04-13 03:17:50 +08:00
parent 6ea03a2515
commit cb4f91bee5
3 changed files with 9 additions and 24 deletions

View File

@@ -164,14 +164,14 @@ class Exam extends NexusModel
return implode("<br/>", $arr);
}
public function begin(): Attribute
protected function beginForUser(): Attribute
{
return new Attribute(
get: fn ($value) => $value ? Carbon::parse($value) : Carbon::now()
);
}
public function end(): Attribute
protected function endForUser(): Attribute
{
return new Attribute(
get: function ($value, $attributes) {
@@ -180,8 +180,8 @@ class Exam extends NexusModel
}
if (!empty($attributes['duration'])) {
/** @var Carbon $begin */
$begin = $this->begin;
return $begin->addDays($attributes['duration']);
$begin = $this->begin_for_user;
return $begin->clone()->addDays($attributes['duration']);
}
throw new \RuntimeException("No specific end or duration");
}