To achieve the desired functionality of rendering widgets under the "Summary" tab without duplicating the page structure, you can refactor your approach to include the widgets directly in the "CompanyOverview" page. Instead of creating a separate page for the summary, you can leverage the getHeaderWidgets() method within the same page or use a dedicated Livewire component for the summary section. Here's how you can do it:
-
Create a Livewire Component for the Summary Tab:
First, create a Livewire component that will handle the rendering of your widgets. This component will be used in the "Summary" tab.
php artisan make:livewire SummaryWidgets -
Implement the Widgets in the Livewire Component:
In the
SummaryWidgetscomponent, you can define the widgets you want to display.// app/Http/Livewire/SummaryWidgets.php namespace App\Http\Livewire; use Livewire\Component; use Filament\Widgets\Widget; class SummaryWidgets extends Component { public function render() { return view('livewire.summary-widgets', [ 'widgets' => $this->getWidgets(), ]); } protected function getWidgets(): array { return [ // Instantiate your widgets here // Example: new SomeWidget(), ]; } } -
Create the Blade View for the Livewire Component:
Create a Blade view for the
SummaryWidgetscomponent to render the widgets.<!-- resources/views/livewire/summary-widgets.blade.php --> <div> @foreach ($widgets as $widget) {{ $widget->render() }} @endforeach </div> -
Include the Livewire Component in the Summary Tab:
Update your "CompanyOverview" page to include the
SummaryWidgetscomponent in the "Summary" tab.<x-filament-panels::page> <div class="flex flex-col gap-4" x-data="{ tab: 'shipments' }"> <x-filament::tabs label="Content tabs"> <x-filament::tabs.item @click="tab = 'shipments'" :alpine-active="'tab === \'shipments\''"> Shipments </x-filament::tabs.item> <x-filament::tabs.item @click="tab = 'summary'" :alpine-active="'tab === \'summary\''"> Summary </x-filament::tabs.item> </x-filament::tabs> <div> <div x-show="tab === 'shipments'" x-cloak> <livewire:intercompany.table-shipment :filters="$filters" /> </div> <div x-show="tab === 'summary'" x-cloak> <livewire:summary-widgets /> </div> </div> </div> </x-filament-panels::page>
By using a Livewire component for the summary section, you can encapsulate the logic and rendering of widgets without duplicating the page structure. This approach allows you to maintain a clean and organized codebase while leveraging the power of Livewire and Filament widgets.