F
Filament2mo ago
o.m

How do I add another button on Resource page?

I wanted to add another button called "Form Settings" beside the "New Form" is it possible in filament? If so how do I approach this problem? So when I click on I get redirected to another page.
class FormResource extends Resource
{
protected static ?string $model = FormModel::class;

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

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('form_number')
->label('#')
->searchable(),
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('courses_count')
->label('# of Associated Courses')
->counts('courses')
->sortable(),
Tables\Columns\TextColumn::make('author.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->formatStateUsing(fn ($state) => \Illuminate\Support\Carbon::parse($state)->format('m/d/Y'))
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Last Updated')
->date('F j, Y')
->sortable(),

])->defaultSort('name', 'asc')
->filters([

])
->actions([
Tables\Actions\EditAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListForms::route('/'),
'create' => Pages\CreateForm::route('/create'),
'edit' => Pages\EditForm::route('/{record}/edit'),
];
}
}
class FormResource extends Resource
{
protected static ?string $model = FormModel::class;

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

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('form_number')
->label('#')
->searchable(),
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('courses_count')
->label('# of Associated Courses')
->counts('courses')
->sortable(),
Tables\Columns\TextColumn::make('author.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->formatStateUsing(fn ($state) => \Illuminate\Support\Carbon::parse($state)->format('m/d/Y'))
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Last Updated')
->date('F j, Y')
->sortable(),

])->defaultSort('name', 'asc')
->filters([

])
->actions([
Tables\Actions\EditAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListForms::route('/'),
'create' => Pages\CreateForm::route('/create'),
'edit' => Pages\EditForm::route('/{record}/edit'),
];
}
}
No description
Solution:
```php protected function getHeaderActions(): array { return [ Actions\Action::make('formSetting')...
Jump to solution
17 Replies
o.m
o.mOP2mo ago
Something like this is what I want to achieve
No description
Dennis Koch
Dennis Koch2mo ago
Add it to the headerAction() on the ListPage
o.m
o.mOP2mo ago
Sorry for the newbish question but I do not have ListPage on my FormsResource. How should I implement it ?
Dennis Koch
Dennis Koch2mo ago
It's called ListForms
o.m
o.mOP2mo ago
I tried searching ListForms on the docs but I do not see anything on the search result in v3.x
Dennis Koch
Dennis Koch2mo ago
Not the docs. Look at your codebase 😅
o.m
o.mOP2mo ago
No description
o.m
o.mOP2mo ago
I am doing it wrong
Dennis Koch
Dennis Koch2mo ago
Check your codebase for ListForms. That's the Livewire. component you are currently looking at. Resources are just a wrapper for common stuff that is reused in other places. The Pages are the actual Livewire components that get rendered.
o.m
o.mOP2mo ago
I think I am getting it now. That this is what you meant
No description
o.m
o.mOP2mo ago
My apologies
Dennis Koch
Dennis Koch2mo ago
Yep. It's always a good start to look at the existing code.
Solution
o.m
o.m2mo ago
protected function getHeaderActions(): array
{
return [
Actions\Action::make('formSetting')
->label('Form Settings')
->icon('heroicon-o-cog')
->button()
->url(route('filament.manage.pages.form-setting'))
->color('primary'),
Actions\CreateAction::make(),
];
}
protected function getHeaderActions(): array
{
return [
Actions\Action::make('formSetting')
->label('Form Settings')
->icon('heroicon-o-cog')
->button()
->url(route('filament.manage.pages.form-setting'))
->color('primary'),
Actions\CreateAction::make(),
];
}
Got it working, thanks!
Dennis Koch
Dennis Koch2mo ago
Better use FormSettingsPage::getUrl() for routes.
o.m
o.mOP2mo ago
Didn't know I COULD DO THAT. Cool, is this a livewire feature
Dennis Koch
Dennis Koch2mo ago
No it's just a function on the pages 😅

Did you find this page helpful?