Skip to content

Commit 2e6cdd4

Browse files
committedJul 29, 2024
Allows developer to extend WorkflowModelStatus class
1 parent 72452ff commit 2e6cdd4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed
 

‎config/workflow.php

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
return [
66
/** @phpstan-ignore-next-line */
77
'user_model' => App\Models\User::class,
8+
'workflow_model_status_class' => Squarebit\Workflows\Models\WorkflowModelStatus::class,
89
'allow_guests_to_transition' => false,
910
];

‎src/Traits/HasWorkflows.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public static function bootHasWorkflows(): void
4444
return;
4545
}
4646

47-
WorkflowModelStatus::query()
47+
$wmsClass = config('workflow.workflow_model_status_class');
48+
$wmsClass::query()
4849
->withTrashed()
4950
->where('model_type', $model->getMorphClass())
5051
->where('model_id', $model->getKey())
@@ -104,7 +105,7 @@ public function getCurrentWorkflow(): ?Workflow
104105
*/
105106
public function modelStatus(): MorphOne
106107
{
107-
return $this->morphOne(WorkflowModelStatus::class, 'model')
108+
return $this->morphOne(config('workflow.workflow_model_status_class'), 'model')
108109
->where('workflow_id', $this->getCurrentWorkflow()?->id);
109110
}
110111

@@ -115,15 +116,15 @@ public function modelStatus(): MorphOne
115116
*/
116117
public function modelStatuses(): MorphMany
117118
{
118-
return $this->morphMany(WorkflowModelStatus::class, 'model');
119+
return $this->morphMany(config('workflow.workflow_model_status_class'), 'model');
119120
}
120121

121122
/**
122123
* @throws Throwable
123124
*/
124125
public function allModelStatus(): MorphMany
125126
{
126-
return $this->morphMany(WorkflowModelStatus::class, 'model')
127+
return $this->morphMany(config('workflow.workflow_model_status_class'), 'model')
127128
->where('workflow_id', $this->getCurrentWorkflow()?->id)
128129
->withTrashed();
129130
}
@@ -224,7 +225,8 @@ public function isInFinalStatus(): bool
224225

225226
protected function createModelStatus(Workflow $workflow, WorkflowStatus $status): WorkflowModelStatus
226227
{
227-
$modelStatus = new WorkflowModelStatus();
228+
$wmsClass = config('workflow.workflow_model_status_class');
229+
$modelStatus = new $wmsClass();
228230
$modelStatus->model()->associate($this);
229231
$modelStatus->user()->associate(Auth::user());
230232
$modelStatus->workflow()->associate($workflow);

‎tests/Support/2000_01_01_000000_create_permission_tables.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
66
use Spatie\Permission\PermissionRegistrar;
77

88
class CreatePermissionTables extends Migration

0 commit comments

Comments
 (0)
Please sign in to comment.