custom widgets

Hi all! I'm trying to build a custom widget which contains, for each Center, each groups with info. I'm not sure I'm doing it right...
class AvailableSlotsStats extends BaseWidget
{
protected static string $view = 'filament.widgets.center-widget';

protected function getViewData(): array
{
return [
'centers' => self::generateStatsPerCenter()
];
}

protected static function generateStatsPerCenter()
{
$selectedAcademicCourse = auth()->user()->current_academic_course_id;
return Center::query()
->whereHas('groups', function ($query) use ($selectedAcademicCourse) {
$query->where('academic_course_id', $selectedAcademicCourse);
})
->get();

}
}
class AvailableSlotsStats extends BaseWidget
{
protected static string $view = 'filament.widgets.center-widget';

protected function getViewData(): array
{
return [
'centers' => self::generateStatsPerCenter()
];
}

protected static function generateStatsPerCenter()
{
$selectedAcademicCourse = auth()->user()->current_academic_course_id;
return Center::query()
->whereHas('groups', function ($query) use ($selectedAcademicCourse) {
$query->where('academic_course_id', $selectedAcademicCourse);
})
->get();

}
}
It shows like in the pic. I have a grid layout but widgets shows like blocks. any ideas? I
No description
3 Replies
tesse05
tesse05OP7mo ago
anyone?
awcodes
awcodes7mo ago
What is in the view file?
tesse05
tesse05OP7mo ago
<div class="mb-4 grid-cols-4">
@foreach($centers as $center)
<x-filament-widgets::widget>
<x-filament::section>
<h1>{{ $center->name }}<h1>
<div>
@custom info
</div>
</x-filament::section>
</x-filament-widgets::widget>
@endforeach
</div>
<div class="mb-4 grid-cols-4">
@foreach($centers as $center)
<x-filament-widgets::widget>
<x-filament::section>
<h1>{{ $center->name }}<h1>
<div>
@custom info
</div>
</x-filament::section>
</x-filament-widgets::widget>
@endforeach
</div>
Should I extend use Filament\Widgets\Widget; instead of use Filament\Widgets\StatsOverviewWidget
Want results from more Discord servers?
Add your server