Redirect After Action in Livewire v4
February 01, 2026
•
1 min read
•
18 views
Table of Contents
Redirect users after form submissions or actions in Livewire v4.
Basic Redirect Methods
class CreatePost extends Component
{
public string $title = '';
public string $content = '';
public function save(): void
{
$post = Post::create([
'title' => $this->title,
'content' => $this->content,
]);
// Simple redirect to URL
$this->redirect('/posts');
// Redirect with SPA-like navigation (no full page reload)
$this->redirect('/posts', navigate: true);
// Redirect to named route
$this->redirectRoute('posts.index');
// Redirect to route with parameters
$this->redirectRoute('posts.show', ['post' => $post->id]);
// Redirect with intended URL (after login)
$this->redirectIntended(default: '/dashboard');
}
}Redirect with Flash Message
public function save(): void
{
Post::create($this->only(['title', 'content']));
session()->flash('success', 'Post created successfully!');
$this->redirect('/posts', navigate: true);
}
// Or use redirect with session helper
public function delete(Post $post): void
{
$post->delete();
return $this->redirectRoute('posts.index')
->with('message', 'Post deleted!');
}Conditional Redirects
public function submit(): void
{
$this->validate();
$user = User::create($this->form);
if ($user->isAdmin()) {
$this->redirectRoute('admin.dashboard');
} else {
$this->redirectRoute('user.dashboard');
}
}
Related Posts
Introduction to Livewire v4: The Future of Laravel Full-Stack Development
Discover what's new in Livewire v4 and why it's a game-changer for Laravel developers.
Single-File Components in Livewire v4: The View-First Approach
Learn how to create single-file components with the new .wire.php extension.
Multi-File Components (MFC) in Livewire v4
Organize complex components with the new multi-file component structure.
Comments (0)
No comments yet. Be the first to comment!