Logo

dev-resources.site

for different kinds of informations.

Filament: Add icon to form buttons

Published at
10/25/2024
Categories
filament
filamentphp
Author
syahzul
Categories
2 categories in total
filament
open
filamentphp
open
Author
7 person written this
syahzul
open
Filament: Add icon to form buttons

In the development of admin panels using Filament PHP, enhancing form button aesthetics can significantly improve the user experience. This tutorial provides guidance on modifying button icons and labels for both Create and Edit forms.

Image description

Create Form

To customise the Create form buttons, access the CreateUser.php file located within your UserResource/Pages directory. There, you can override the relevant functions to make your desired adjustments. By implementing these changes, you can tailor the buttons to better fit the design and functionality needs of your application.

<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\CreateRecord;
use Filament\Support\Enums\IconPosition;

class CreateUser extends CreateRecord
{
    protected static string $resource = UserResource::class;

    // Customise the "Create" button
    protected function getCreateFormAction(): Action
    {
        return parent::getCreateFormAction()
            ->label('Add New User')
            ->icon('heroicon-o-user-plus')
            ->iconPosition(IconPosition::Before);
    }

    // Customise the "Create & Create Another" button
    protected function getCreateAnotherFormAction(): Action
    {
        return parent::getCreateAnotherFormAction()
            ->label('Save & Create Another')
            ->icon('heroicon-o-plus-circle')
            ->iconPosition(IconPosition::Before);
    }

    // Customise the "Cancel" button
    protected function getCancelFormAction(): Action
    {
        return parent::getCancelFormAction()
            ->label('Go Back')
            ->icon('heroicon-o-arrow-left')
            ->color('gray');
    }
}
Enter fullscreen mode Exit fullscreen mode

Edit Form

For the Edit form buttons, you'll need to modify the EditUser.php file in your UserResource/Pages directory:

<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\EditRecord;
use Filament\Support\Enums\IconPosition;

class EditUser extends EditRecord
{
    protected static string $resource = UserResource::class;

    // Customize the "Save" button
    protected function getSaveFormAction(): Action
    {
        return parent::getSaveFormAction()
            ->label('Update User')
            ->icon('heroicon-o-check-circle')
            ->iconPosition(IconPosition::Before)
            ->color('success');
    }

    // Customize the "Cancel" button
    protected function getCancelFormAction(): Action
    {
        return parent::getCancelFormAction()
            ->label('Go Back')
            ->icon('heroicon-o-arrow-left')
            ->color('gray');
    }
}
Enter fullscreen mode Exit fullscreen mode

Customising form buttons in Filament PHP is straightforward and can greatly improve your admin panel's usability. By overriding these methods, you can create a more intuitive and visually appealing interface for your users.

Remember to import the necessary classes and ensure your namespace matches your application's structure. The changes will take effect immediately after saving the files.

filament Article's
30 articles in total
Favicon
Multi select default selection i filament v3
Favicon
Filament: Image Color Picker component
Favicon
My First No-Code SaaS Took off - $8K in 40 days
Favicon
Add a sidebar with options in a Filament resource
Favicon
Filament: Modify login or logout response
Favicon
Filament Database Notification Sound
Favicon
Laravel Nova vs Filament: The Best Admin Panels
Favicon
Filament: Add icon to form buttons
Favicon
Filament Breezy: add new field to Personal Info component
Favicon
Filament: Delete Attachments when Deleting a Record
Favicon
Filament: Generate Resource from Existing DB Schema
Favicon
Filament Breezy: set storage disk for avatar
Favicon
Laravel Stats : Filament Charts.js pour faire les statistiques
Favicon
Filament How to redirect to list page after (create,update) using Trait
Favicon
How to solve Symfony\Component\Routing\Exception\RouteNotFoundException Route [filament.admin.resources.api-keys.index] not
Favicon
Apa itu Laravel Filament?
Favicon
Laravel Filament: get resource table data by authenticated id
Favicon
Change Default Colors in FilamentPHP
Favicon
How to Use Searchable in Laravel 10 Filament v3
Favicon
Filament: add a confirmation password field in a form
Favicon
TomatoPHP Filament Plugins
Favicon
Debug Filament Search Query
Favicon
Filament PHP Blade UI Components Visually Explained
Favicon
Filament Context Menu
Favicon
How to Extend a Filament Resource
Favicon
Linkeeper - Lesson 02 - Start playing with Filament
Favicon
Linkeeper - Lesson 01 - Installation
Favicon
Filament has SPA mode!
Favicon
Access parent component value from the Repeater in Filament
Favicon
Filament v3 - Multi-tenancy form component scoping

Featured ones: