Skip to content

Commit df904e0

Browse files
feat:[LAR-134] Make create and Edit Thread in Action
1 parent 531b299 commit df904e0

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

app/Actions/Forum/UpdateThreadAction.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
final class UpdateThreadAction
1111
{
12-
public function execute(array $formValues, int $threadId): Thread
12+
public function execute(array $formValues, Thread $thread): Thread
1313
{
14-
return DB::transaction(function () use ($formValues, $threadId) {
15-
16-
$thread = Thread::query()->findOrFail($threadId);
14+
return DB::transaction(function () use ($formValues, $thread) {
1715

1816
$thread->update($formValues);
1917

app/Livewire/Components/Slideovers/ThreadForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function save(): void
122122
$validated = $this->form->getState();
123123

124124
$thread = ($this->thread?->id)
125-
? app(UpdateThreadAction::class)->execute($validated, $this->thread->id)
125+
? app(UpdateThreadAction::class)->execute($validated, $this->thread)
126126
: app(CreateThreadAction::class)->execute($validated);
127127

128128
$this->form->model($thread)->saveRelationships();

tests/Feature/Actions/Forum/CreateThreadActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'slug' => 'thread-title',
2727
'user_id' => $this->user->id,
2828
'body' => 'This is a test action thread for created or updated thread.',
29-
'channels' => [$channels->first(), $channels->last()],
29+
'channels' => [$channels->modelKeys()],
3030
]);
3131

3232
expect($thread)

tests/Feature/Actions/Forum/UpdateThreadActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
$thread = app(UpdateThreadAction::class)->execute([
2828
'title' => 'update thread title',
29-
], $thread->id);
29+
], $thread);
3030

3131
expect($thread)
3232
->toBeInstanceOf(Thread::class)

0 commit comments

Comments
 (0)