skip to Main Content

I want to add extra fields to roles in package filament-authentication

I am only able to add it in migrations

Its says its has extendable resource views but doesn’t mention how to extend it
https://filamentphp.com/plugins/user-role-resource-management

I am new to laravel filamentphp

Can anyone guide me how to do it?

3

Answers


  1. Chosen as BEST ANSWER

    The point every answer is missing is that all packages have a config file that's published in config directory.

    In order to extend a package we just have to create a new Resource/Page, inherit and override it's functionality.

    Finally, we need to replace path/namesapce in the config of that package with the new Resource/Page we just override.


  2. To add extra fields to roles in the Filament Authentication package, you need to perform the following steps:

    Create a new migration: Run the following command in your terminal to generate a new migration file:

    php artisan filament: migration
    

    Open the generated migration file: You’ll find the migration file in the database/migrations directory. Open the file and locate the up method.

    Inside the up method, you can use the table method provided by Laravel to add extra fields to the roles table. For example, if you want to add a description field to the roles table, you can use the text column type:

    Schema::table('roles', function (Blueprint $table) {
        $table->text('description')->nullable();
    });
    

    Feel free to add any additional fields you need.

    Run the migration: Execute the following command to run the migration and apply the changes to the database:

    php artisan migrate
    

    This will add the new fields to the roles table in the database.

    Update the resource view: To display and manage the extra fields in the Filament resource view, you need to modify the corresponding resource file. By default, the resource file for roles is located at app/Filament/Resources/RoleResource.php. Open this file.

    Inside the fields method of the RoleResource class, you can add the new fields. For example, if you added a description field, you can include it as follows:

    public function fields()
    {
        return [
            // Existing fields...
            Textarea::make('Description'),
        ];
    }
    

    Customize the field type and options based on your requirements.

    Save the changes to the RoleResource file.

    With these steps, you have added extra fields to the roles table and configured the Filament resource view to display and manage those fields. Now, when you access the role management section in your Filament application, you should see the new fields for roles.

    Login or Signup to reply.
  3. If you want to add extra fields, first add your columns using migrations – if want to add.

    OR

    To extend the package layout, you can create a new Filament Page and extends the Package view.

    Steps

    Create a new page using php artisan make:filament-page Profile
    – don’t attach with any resource

    It will create a file inside the AppFilamentPagesProfile.php

    
    <?php
    
    namespace AppFilamentPages;
    
    use FilamentPagesPage;
    use PhpsaFilamentAuthenticationPagesProfile as PagesProfile;
    
    class Profile extends PagesProfile
    {
        // 
    }
    
    

    You can follow more details on this link, how to extend package functionality and view.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search