fix: delete post redirects to posts index instead of back() which causes 404

This commit is contained in:
Paulo Castellano 2026-04-01 15:04:13 -03:00
parent 4e6a2dace1
commit 146bd7b7d2
6 changed files with 19 additions and 18 deletions

View file

@ -257,6 +257,6 @@ public function destroy(Request $request, Post $post): RedirectResponse
}
}
return back();
return redirect()->route('app.posts.index');
}
}

1
lang/php_en.json Normal file

File diff suppressed because one or more lines are too long

1
lang/php_es.json Normal file

File diff suppressed because one or more lines are too long

1
lang/php_pt-BR.json Normal file

File diff suppressed because one or more lines are too long

View file

@ -75,7 +75,7 @@ function closeWindow() {
}
// Close after a short delay
setTimeout(closeWindow, 5000);
setTimeout(closeWindow, 6000);
// If still open after 2 seconds, show manual close message
setTimeout(function() {

View file

@ -297,34 +297,32 @@
$response->assertRedirect(route('login'));
});
test('destroy post deletes the post and redirects back', function () {
test('destroy post deletes the post and redirects to posts index', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$response = $this->actingAs($this->user)
->from(route('app.calendar'))
->delete(route('app.posts.destroy', $post));
$response->assertRedirect(route('app.posts.index'));
expect(Post::find($post->id))->toBeNull();
});
test('destroy post with redirect param redirects to calendar', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$response = $this->actingAs($this->user)
->delete(route('app.posts.destroy', $post).'?redirect=app.calendar');
$response->assertRedirect(route('app.calendar'));
expect(Post::find($post->id))->toBeNull();
});
test('destroy post from status filter redirects back to filter', function (string $status) {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$response = $this->actingAs($this->user)
->from(route('app.posts.index', ['status' => $status]))
->delete(route('app.posts.destroy', $post));
$response->assertRedirect(route('app.posts.index', ['status' => $status]));
expect(Post::find($post->id))->toBeNull();
})->with(['draft', 'scheduled', 'published']);
test('destroy post with redirect param redirects to specified route', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,