each user has different widget

i would like to show on dashboard the widgets of that user Auth::user()->widgets() ....
9 Replies
Patrick Boivin
Patrick Boivin17mo ago
Filament
Getting started - Dashboard - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
marco76tv
marco76tvOP17mo ago
can you show me an example please ?
Dan Harrin
Dan Harrin17mo ago
what is Auth::user()->widgets()
marco76tv
marco76tvOP17mo ago
marco76tv
marco76tvOP17mo ago
i have created a custom dashboard .. now i must pass a variable to "AdminWidgets"
malebestia.
malebestia.17mo ago
that would be really very useful
Dan Harrin
Dan Harrin17mo ago
what do you want filament to provide you with to achieve this
marco76tv
marco76tvOP17mo ago
each user has several graphs, and I have to pass the question id to the widget
malebestia.
malebestia.17mo ago
this is a found solution, even if I don't really like it and that it could be done better
in laravel\config\filament.php dashboard changed
'pages' => [
'namespace' => 'App\\Filament\\Pages',
'path' => app_path('Filament/Pages'),
'register' => [
\Modules\MyModule\Filament\Pages\Dashboard::class,
],
],
'pages' => [
'namespace' => 'App\\Filament\\Pages',
'path' => app_path('Filament/Pages'),
'register' => [
\Modules\MyModule\Filament\Pages\Dashboard::class,
],
],
laravel\Modules\MyModule\Filament\Pages\Dashboard.php
<?php

namespace Modules\MyModule\Filament\Pages;

use Filament\Pages\Dashboard as BasePage;
use Modules\MyModule\Models\QuestionChart;
use Illuminate\Database\Eloquent\Collection;
use Modules\MyModule\Filament\Widgets\ChartsWidget;
use Modules\MyModule\Filament\Widgets\StatsOverview;
use Modules\MyModule\Filament\Widgets\ChartsOverview;
use Modules\MyModule\Filament\Resources\QuestionChartResource\Widgets\WidgetTest;

class Dashboard extends BasePage
{
public function getWidgets(): array{
return [
ChartsWidget::class,
];
}

}
<?php

namespace Modules\MyModule\Filament\Pages;

use Filament\Pages\Dashboard as BasePage;
use Modules\MyModule\Models\QuestionChart;
use Illuminate\Database\Eloquent\Collection;
use Modules\MyModule\Filament\Widgets\ChartsWidget;
use Modules\MyModule\Filament\Widgets\StatsOverview;
use Modules\MyModule\Filament\Widgets\ChartsOverview;
use Modules\MyModule\Filament\Resources\QuestionChartResource\Widgets\WidgetTest;

class Dashboard extends BasePage
{
public function getWidgets(): array{
return [
ChartsWidget::class,
];
}

}
laravel\Modules\MyModule\Filament\Widgets\ChartsWidget.php
where I pass the parameters I need, in this case the ids
<?php

namespace Modules\MyModule\Filament\Widgets;

use Filament\Widgets\Widget;

class ChartsWidget extends Widget
{
protected static string $view = 'MyModule::filament.widgets.charts';

public function getQuestionCharts(){
return [4,5,6];
}
}
<?php

namespace Modules\MyModule\Filament\Widgets;

use Filament\Widgets\Widget;

class ChartsWidget extends Widget
{
protected static string $view = 'MyModule::filament.widgets.charts';

public function getQuestionCharts(){
return [4,5,6];
}
}
his blade
<x-filament::widget>
@foreach($this->getQuestionCharts() as $questionChart)
<x-filament::card >
<livewire:question-chart :questionChartId="$questionChart" />
</x-filament::card>
@endforeach
</x-filament::widget>
<x-filament::widget>
@foreach($this->getQuestionCharts() as $questionChart)
<x-filament::card >
<livewire:question-chart :questionChartId="$questionChart" />
</x-filament::card>
@endforeach
</x-filament::widget>
component created and called laravel\Modules\MyModule\Http\Livewire\QuestionChart.php
<?php

declare(strict_types=1);

namespace Modules\MyModule\Http\Livewire;

use Livewire\Component;
use Filament\Widgets\ChartWidget;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Collection;
/**
* ---.
*/
class QuestionChart extends /*Component*/ ChartWidget {

public string $questionChartId;

public function mount(){
parent::mount();
[$questionChartId]=func_get_args();
$this->questionChartId=strval($questionChartId);
}

protected function getType(): string
{
return 'line';
}

protected function getHeading(): string
{
return 'questionChartId['.$this->questionChartId.']';
}

protected function getData(): array
{
return [
'datasets' => [
[
'label' => 'Blog posts created',
'data' => [0, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
],
],
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
];
}
}
<?php

declare(strict_types=1);

namespace Modules\MyModule\Http\Livewire;

use Livewire\Component;
use Filament\Widgets\ChartWidget;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Collection;
/**
* ---.
*/
class QuestionChart extends /*Component*/ ChartWidget {

public string $questionChartId;

public function mount(){
parent::mount();
[$questionChartId]=func_get_args();
$this->questionChartId=strval($questionChartId);
}

protected function getType(): string
{
return 'line';
}

protected function getHeading(): string
{
return 'questionChartId['.$this->questionChartId.']';
}

protected function getData(): array
{
return [
'datasets' => [
[
'label' => 'Blog posts created',
'data' => [0, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
],
],
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
];
}
}
I repeat, it is a solution, but it could be done better
Want results from more Discord servers?
Add your server