|
23 | 23 | * @method static Builder fromTo(WorkflowStatus $from, WorkflowStatus $to)
|
24 | 24 | * @method static Builder entry()
|
25 | 25 | * @method static Builder exit()
|
| 26 | + * |
26 | 27 | */
|
27 | 28 | class WorkflowTransition extends Model
|
28 | 29 | {
|
29 | 30 | use SoftDeletes;
|
| 31 | + /** @use BelongsToWorkflow<WorkflowTransition> */ |
30 | 32 | use BelongsToWorkflow;
|
31 | 33 | use HasPermissions;
|
32 | 34 |
|
33 | 35 | public string $guard_name = 'web';
|
34 | 36 |
|
35 |
| - public function getMorphClass():string |
| 37 | + protected $table = 'workflow_transitions'; |
| 38 | + |
| 39 | + public function getMorphClass(): string |
36 | 40 | {
|
37 | 41 | return 'Workflow.WorkflowTransition';
|
38 | 42 | }
|
39 | 43 |
|
40 |
| - protected $table = 'workflow_transitions'; |
41 |
| - |
| 44 | + /** |
| 45 | + * @return BelongsTo<WorkflowStatus, WorkflowTransition> |
| 46 | + */ |
42 | 47 | public function fromStatus(): BelongsTo
|
43 | 48 | {
|
44 | 49 | return $this->belongsTo(WorkflowStatus::class, 'from_id');
|
45 | 50 | }
|
46 | 51 |
|
| 52 | + /** |
| 53 | + * @return BelongsTo<WorkflowStatus, WorkflowTransition> |
| 54 | + */ |
47 | 55 | public function toStatus(): BelongsTo
|
48 | 56 | {
|
49 | 57 | return $this->belongsTo(WorkflowStatus::class, 'to_id');
|
50 | 58 | }
|
51 | 59 |
|
| 60 | + /** |
| 61 | + * @param Builder<WorkflowTransition> $query |
| 62 | + * @return Builder<WorkflowTransition> |
| 63 | + */ |
52 | 64 | public function scopeFrom(Builder $query, ?WorkflowStatus $from): Builder
|
53 | 65 | {
|
54 | 66 | return $query->where('from_id', $from?->id);
|
55 | 67 | }
|
56 | 68 |
|
| 69 | + /** |
| 70 | + * @param Builder<WorkflowTransition> $query |
| 71 | + * @return Builder<WorkflowTransition> |
| 72 | + */ |
57 | 73 | public function scopeTo(Builder $query, ?WorkflowStatus $to): Builder
|
58 | 74 | {
|
59 | 75 | return $query->where('to_id', $to?->id);
|
60 | 76 | }
|
61 | 77 |
|
| 78 | + /** |
| 79 | + * @param Builder<WorkflowTransition> $query |
| 80 | + * @return Builder<WorkflowTransition> |
| 81 | + */ |
62 | 82 | public function scopeFromTo(Builder $query, ?WorkflowStatus $from, ?WorkflowStatus $to): Builder
|
63 | 83 | {
|
64 |
| - return $query->from($from)->to($to); |
| 84 | + return $query->from($from) |
| 85 | + ->to($to); |
65 | 86 | }
|
66 | 87 |
|
| 88 | + /** |
| 89 | + * @param Builder<WorkflowTransition> $query |
| 90 | + * @return Builder<WorkflowTransition> |
| 91 | + */ |
67 | 92 | public function scopeEntry(Builder $query): Builder
|
68 | 93 | {
|
69 | 94 | return $query->whereNull('from_id');
|
70 | 95 | }
|
71 | 96 |
|
| 97 | + /** |
| 98 | + * @param Builder<WorkflowTransition> $query |
| 99 | + * @return Builder<WorkflowTransition> |
| 100 | + */ |
72 | 101 | public function scopeExit(Builder $query): Builder
|
73 | 102 | {
|
74 | 103 | return $query->whereNull('to_id');
|
75 | 104 | }
|
76 | 105 |
|
77 | 106 | public function __toString()
|
78 | 107 | {
|
79 |
| - return $this->workflow.': '.($this->fromStatus ?? 'o').' -> '.($this->toStatus ?? 'x'); |
| 108 | + return $this->workflow . ': ' . ($this->fromStatus ?? 'o') . ' -> ' . ($this->toStatus ?? 'x'); |
80 | 109 | }
|
81 | 110 | }
|
0 commit comments