Skip to content

Commit 6aeaec8

Browse files
committed
latest, oldest
1 parent bda3c23 commit 6aeaec8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Traits/HasProcesses.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
use Yuges\Processable\Config\Config;
77
use Yuges\Processable\Models\Process;
88
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\Relations\MorphOne;
910
use Illuminate\Database\Eloquent\Relations\MorphMany;
1011
use Yuges\Processable\Interfaces\Process as ProcessInterface;
1112

1213
/**
1314
* @property Collection<array-key, Process> $processes
15+
* @property ?Process $latestProcess
16+
* @property ?Process $oldestProcess
1417
*/
1518
trait HasProcesses
1619
{
@@ -35,4 +38,14 @@ public function process(string $process): Process
3538
Config::getCreateProcessAction($this)->execute($process)
3639
);
3740
}
41+
42+
public function latestProcess(): MorphOne
43+
{
44+
return $this->processes()->one()->latestOfMany();
45+
}
46+
47+
public function oldestProcess(): MorphOne
48+
{
49+
return $this->processes()->one()->oldestOfMany();
50+
}
3851
}

src/Traits/HasStages.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
use Yuges\Processable\Config\Config;
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Collection;
9+
use Illuminate\Database\Eloquent\Relations\HasOne;
910
use Illuminate\Database\Eloquent\Relations\HasMany;
1011

1112
/**
1213
* @property Collection<array-key, Stage> $stages
14+
* @property ?Stage $latestStage
15+
* @property ?Stage $oldestStage
1316
*/
1417
trait HasStages
1518
{
@@ -18,4 +21,14 @@ public function stages(): HasMany
1821
/** @var Model $this */
1922
return $this->hasMany(Config::getStageClass(Stage::class));
2023
}
24+
25+
public function latestStage(): HasOne
26+
{
27+
return $this->stages()->one()->latestOfMany();
28+
}
29+
30+
public function oldestStage(): HasOne
31+
{
32+
return $this->stages()->one()->oldestOfMany();
33+
}
2134
}

0 commit comments

Comments
 (0)