Panos.S
Panos.S
FFilament
Created by Panos.S on 10/26/2024 in #❓┊help
Navigation sidebar is empty even though my resources have a navigation group
No description
2 replies
FFilament
Created by Panos.S on 10/22/2024 in #❓┊help
Header Action filter not applying to Table Widget
Hello, I have created a custom page which extends the default Filament\Pages\Page and added a Header Action Filter Action filter like hoping to apply the filter on a custom table widget I have created. This setup works pretty well with chart widgets but this doesn't seem to be the case for table widgets. This is the Page class:
class Commissions extends Page
{
use HasFiltersAction, HasFiltersForm;

protected static ?string $navigationIcon = 'heroicon-o-banknotes';

protected static string $view = 'filament.pages.commissions';

protected static ?string $navigationGroup = 'On-Site';

public $year; // Declare year property to hold the selected year

protected function getHeaderActions(): array
{
return [
FilterAction::make()
->form([
Select::make('year')
->options([
2024 => '2024',
2023 => '2023',
2022 => '2022',
'all' => 'All',
])
->native(false)
->afterStateUpdated(function ($state){
$this->year = $state; // Set the selected year
$this->updateWidgets(); // Update the widgets with the new filter
}),
]),
];
}

protected function updateWidgets()
{
$this->dispatch('filtersUpdated', [
'year' => $this->year, // Dispatch the year state when the filter is updated
]);
}
}
class Commissions extends Page
{
use HasFiltersAction, HasFiltersForm;

protected static ?string $navigationIcon = 'heroicon-o-banknotes';

protected static string $view = 'filament.pages.commissions';

protected static ?string $navigationGroup = 'On-Site';

public $year; // Declare year property to hold the selected year

protected function getHeaderActions(): array
{
return [
FilterAction::make()
->form([
Select::make('year')
->options([
2024 => '2024',
2023 => '2023',
2022 => '2022',
'all' => 'All',
])
->native(false)
->afterStateUpdated(function ($state){
$this->year = $state; // Set the selected year
$this->updateWidgets(); // Update the widgets with the new filter
}),
]),
];
}

protected function updateWidgets()
{
$this->dispatch('filtersUpdated', [
'year' => $this->year, // Dispatch the year state when the filter is updated
]);
}
}
This is the widget class:
class CommissionsTableChart extends BaseWidget
{
use InteractsWithPageFilters;

protected static ?string $pollingInterval = null;

protected static ?string $heading = 'Commissions by Source'; // Default value for year

protected static bool $isDiscovered = false;

public $year;

protected $listeners = ['filtersUpdated' => 'updateFilters'];

public function updateFilters($filters): void
{
$this->year = $filters['year']; // Update the year from the filters
$this->resetPage();
}

public function table(Table $table): Table
{
// Retrieve the year filter, defaulting to 'all' if not set
$year = $this->year;

return $table
->query(
Registration::query()
->when($year !== 'all' && ! empty($year), function (Builder $query) use ($year) {
$query->whereYear('reservation_date', '=', $year);
})
class CommissionsTableChart extends BaseWidget
{
use InteractsWithPageFilters;

protected static ?string $pollingInterval = null;

protected static ?string $heading = 'Commissions by Source'; // Default value for year

protected static bool $isDiscovered = false;

public $year;

protected $listeners = ['filtersUpdated' => 'updateFilters'];

public function updateFilters($filters): void
{
$this->year = $filters['year']; // Update the year from the filters
$this->resetPage();
}

public function table(Table $table): Table
{
// Retrieve the year filter, defaulting to 'all' if not set
$year = $this->year;

return $table
->query(
Registration::query()
->when($year !== 'all' && ! empty($year), function (Builder $query) use ($year) {
$query->whereYear('reservation_date', '=', $year);
})
As you can see in the attached screenshare, only when I reclick the "filter" header action the page is actually refreshed with the year filtered. Thanks a lot!
2 replies
FFilament
Created by Panos.S on 6/9/2024 in #❓┊help
Create custom resource view blade page and access model attributes
Hello, I am trying to build a custom blade page that will act as a view page of my Classified resource. This is my view-classified.blade.php:
<x-filament-panels::page>
<x-filament::section>
<x-slot name="heading">
Classified Details
</x-slot>

{{-- Content --}}
<div>

<h2>{{ $record->make }}</h2>
<p>{{ $record->model }}</p>
<p>{{ $record->fuel_type }}</p>
<!-- Access other properties as needed -->
</div>
</x-filament::section>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament::section>
<x-slot name="heading">
Classified Details
</x-slot>

{{-- Content --}}
<div>

<h2>{{ $record->make }}</h2>
<p>{{ $record->model }}</p>
<p>{{ $record->fuel_type }}</p>
<!-- Access other properties as needed -->
</div>
</x-filament::section>
</x-filament-panels::page>
I have registered the page in the resource but I can't see how to access the model's attributes and I get the error: Undefined variable $record when trying to access the page
1 replies