You can include one component into another component in Livewire. Let's imagine we have one component for listing comments, inside it, we have a component to show a comment. So each comment is a Livewire component. There is one crucial aspect to know when adding a nested component.
So we have a Livewire component, CommentsList
, where we get the comments, order them and do other needed tasks. Then in the Blade, we show them like so:
resources/views/livewire/comments-list.blade.php:
<div> @foreach ($comments as $comment) <livewire:comment-show :$comment wire:key="{{ $comment->id }}" /> @endforeach</div>
Nothing particular here in the Blade file. The only thing Livewire says...