Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit b0818c5

Browse files
authored
Mention RestoreCurrentSite trait in readme
1 parent d098fc2 commit b0818c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ class ShowContact extends Component
121121

122122
The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components)
123123

124+
### Multi-Site
125+
When using Livewire in a Multi-Site context, the current site gets lost between requests. There is a trait (`\Jonassiewertsen\Livewire\RestoreCurrentSite`) to solve that. Just include it in your component and use `Site::current()` as you normally do.
126+
```php
127+
class ShowArticles extends Component
128+
{
129+
use \Jonassiewertsen\Livewire\RestoreCurrentSite;
130+
131+
protected function entries()
132+
{
133+
return Entry::query()
134+
->where('collection', 'articles')
135+
->where('site', Site::current())
136+
->get();
137+
}
138+
139+
public function render()
140+
{
141+
return view('livewire.blog-entries', $this->entries());
142+
}
143+
}
144+
```
145+
124146
### Paginating Data
125147
You can paginate results by using the WithPagination trait.
126148

0 commit comments

Comments
 (0)