0%

Passing Route Parameter To Livewire View

If you want passing route parameter to Livewire view, you can use the following method.

Change your route web.php pass route parameter to the view

1
2
3
Route::get('/posts/{id}', function ($id) {
return view('livewire.posts.home', compact('id'));
})->name('posts');

Change your view blade file posts/home.blade.php, find where you call your livewire component add the parameter to it

1
<livewire:show-post :id="$id" />

Receiving parameter from your component, you can get parameter from mount method

1
2
3
4
5
6
7
8
9
10
11
class ShowPost extends Component
{
public $post;

public function mount($id)
{
$this->post = Post::find($id);
}

...
}

Ref