From b0818c5f128ac96d4f17d6a769dc13e284bee26d Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 8 Mar 2024 10:30:57 +0100 Subject: [PATCH] Mention `RestoreCurrentSite` trait in readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 336449d..9caeaf0 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,28 @@ class ShowContact extends Component The [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components) +### Multi-Site +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. +```php +class ShowArticles extends Component +{ + use \Jonassiewertsen\Livewire\RestoreCurrentSite; + + protected function entries() + { + return Entry::query() + ->where('collection', 'articles') + ->where('site', Site::current()) + ->get(); + } + + public function render() + { + return view('livewire.blog-entries', $this->entries()); + } +} +``` + ### Paginating Data You can paginate results by using the WithPagination trait.