fix: redirect to posts list when deleting post from edit page

This commit is contained in:
Paulo Castellano 2026-01-26 13:57:48 -03:00
parent 4fa1cb32dc
commit 44f9f67b7d
3 changed files with 13 additions and 2 deletions

View file

@ -291,6 +291,10 @@ public function destroy(Request $request, Post $post): RedirectResponse
session()->flash('flash.banner', __('posts.flash.deleted'));
session()->flash('flash.bannerStyle', 'success');
if ($redirect = $request->input('redirect')) {
return redirect()->route($redirect);
}
return back();
}
}

View file

@ -56,14 +56,19 @@ const emit = defineEmits(['deleted', 'closed']);
const isOpen = ref<boolean>(false);
const loading = ref<boolean>(false);
const url = ref<string | null>(null);
const redirect = ref<string | null>(null);
function remove() {
if (!url.value) return;
loading.value = true;
const targetUrl = redirect.value
? `${url.value}?redirect=${encodeURIComponent(redirect.value)}`
: url.value;
router[props.method as 'delete' | 'get' | 'post' | 'put' | 'patch'](
url.value,
targetUrl,
{},
{
preserveState: props.preserveState,
@ -82,8 +87,9 @@ function remove() {
);
}
function open(data: { url: string }) {
function open(data: { url: string; redirect?: string }) {
url.value = data.url;
redirect.value = data.redirect ?? null;
loading.value = false;
isOpen.value = true;
}

View file

@ -627,6 +627,7 @@ const deletePost = () => {
if (isReadOnly.value) return;
deleteModal.value?.open({
url: destroyPost.url(post.value.id),
redirect: 'posts.index',
});
};
</script>