jrdavidson's avatar

Livewire Sibling Components Sharing Data

I"m trying to learn to do some additional things with my livewire components so that they can communicate together. What I would like to do is echo out the total number of active users in the span and be able to pass in the entity to display, in this case, Users would be the entity. The reason for that is because this used on multiple pages.

<livewire:data-tables-total>
... 
... // More HTML
<livewire:active-users>
<?php

namespace App\Http\Livewire\Users;

use App\Models\User;
use Livewire\Component;
use Livewire\WithPagination;

class ActiveUsers extends Component
{
    use WithPagination;

    public $perPage = 10;

    public function paginationView()
    {
        return 'pagination.datatables';
    }

    public function render()
    {
        return view('livewire.users.active-users', [
            'activeUsers => User::active()->withActivatedAtDate()->paginate($this->perPage)
        ]);
    }
}
<?php

namespace App\Http\Livewire;

use Livewire\Component;

class DataTablesTotal extends Component
{
    public $recordsTotal = 0;
    public $entity;

    public function render()
    {
        return view('livewire.data-tables-total');
    }
}
<span class="kt-subheader__desc">
    {{ $recordsTotal  }} Total {{ $entity }}
</span>

0 likes
1 reply
jrdavidson's avatar

Has anyone used Livewire for this type of functionality?

Please or to participate in this conversation.