Duplicated Widget
For some reason, I've just created a new widget, but it's duplicating the content twice, and Im not sure whats causing it.
Dashboard.php
<?php
namespace App\Filament\Pages;
use App\Filament\Widgets\StatsOverview;
use App\Filament\Widgets\TwoFactorWidget;
use Filament\Widgets\AccountWidget;
class Dashboard extends \Filament\Pages\Dashboard
{
protected function getHeaderWidgets(): array
{
return [
AccountWidget::make(),
TwoFactorWidget::make(),
];
}
}
<?php
namespace App\Filament\Pages;
use App\Filament\Widgets\StatsOverview;
use App\Filament\Widgets\TwoFactorWidget;
use Filament\Widgets\AccountWidget;
class Dashboard extends \Filament\Pages\Dashboard
{
protected function getHeaderWidgets(): array
{
return [
AccountWidget::make(),
TwoFactorWidget::make(),
];
}
}
4 Replies
My widget Class
My view:
Oh, if I remove it from dashboard getHeaderWidgets... one of them disappears....
SO where is it originally coming from?
<?php
namespace App\Filament\Widgets;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;
use Arch\TwoFactorAuth\Models\TwoFaMethods;
class TwoFactorWidget extends Widget
{
protected static ?int $sort = -3;
protected static bool $isLazy = false;
/**
* @var view-string
*/
protected static string $view = 'widgets.two-factor-widget';
public function render(): View
{
$methods = TwoFaMethods::where('user_id', auth()->user()->getKey())->where('enabled', true)->get();
if ($methods->count() !== 0) {
$desc = 'Enabled';
$color = 'success';
$icon = 'heroicon-m-check-circle';
} else {
$desc = 'Disabled';
$color = 'danger';
$icon = 'heroicon-m-x-circle';
}
return view(static::$view, [
'desc' => $desc,
'color' => $color,
'icon' => $icon,
]);
}
}
<?php
namespace App\Filament\Widgets;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;
use Arch\TwoFactorAuth\Models\TwoFaMethods;
class TwoFactorWidget extends Widget
{
protected static ?int $sort = -3;
protected static bool $isLazy = false;
/**
* @var view-string
*/
protected static string $view = 'widgets.two-factor-widget';
public function render(): View
{
$methods = TwoFaMethods::where('user_id', auth()->user()->getKey())->where('enabled', true)->get();
if ($methods->count() !== 0) {
$desc = 'Enabled';
$color = 'success';
$icon = 'heroicon-m-check-circle';
} else {
$desc = 'Disabled';
$color = 'danger';
$icon = 'heroicon-m-x-circle';
}
return view(static::$view, [
'desc' => $desc,
'color' => $color,
'icon' => $icon,
]);
}
}
@php
$user = filament()->auth()->user();
@endphp
<x-filament-widgets::widget class="fi-account-widget">
<x-filament::section>
<div class="flex items-center gap-x-3">
<div class="flex-1">
<h2 class="grid flex-1 text-base font-semibold leading-6 text-gray-950 dark:text-white">
Multifactor Authentication
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ $desc }}
</p>
</div>
</div>
</x-filament::section>
</x-filament-widgets::widget>
@php
$user = filament()->auth()->user();
@endphp
<x-filament-widgets::widget class="fi-account-widget">
<x-filament::section>
<div class="flex items-center gap-x-3">
<div class="flex-1">
<h2 class="grid flex-1 text-base font-semibold leading-6 text-gray-950 dark:text-white">
Multifactor Authentication
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ $desc }}
</p>
</div>
</div>
</x-filament::section>
</x-filament-widgets::widget>
panel ?
probably
you have it loaded, and one is auto discovered
in your adminPanelProvider, do you have a line like ?
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
Yeah, It may well have been this :).