Hi @luddinus
If you are redirecting in the JS, you can still use your api endpoint to set a flash session, and it will still be available after the redirect.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm using my Api in my web application.
For example, a form that creates a new Post.
// Api/PostsController.php
public function store()
{
$post = Post::create(request()->all());
return ['success' => true];
}
My first approach is to redirect to the same page with a "success" flag when the request is successful (post is created)
axios.post('api/posts', formData).then(response => {
window.location.href = '/posts?success';
});
And then in the WebController that shows the form, show a successful message when the request has the "success" flag.
// Web/PostsController
public function create()
{
if (request()->has('success') {
flash('Post created successfully');
}
return view('posts.create');
}
Any more aproaches?
Thanks.
Please or to participate in this conversation.