Skip to content

kgalanos/filament-user

Repository files navigation

Add username or email to login filamentphp panel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Add fields ulid(do not remove id),username,phone and phone_verified_at to User Model and you may login with username/email in filamentphp panel. Also installs and configure

        "alperenersoy/filament-export": "*",
        "stechstudio/filament-impersonate": "^3.0",
        "bezhansalleh/filament-shield": "*"

Installation

You can install the package via composer:

composer require kgalanos/filament-user

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-user-migrations"
php artisan migrate

You can update Model User in config\auth.php with:

'model' => \Kgalanos\FilamentUser\Models\User::class,

or you can update

App\Models\User
with
class User extends \Kgalanos\FilamentUser\Models\User implements FilamentUser
{
    use HasFilamentShield, HasRoles;
     /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'username',
        'avatar_url',
        'phone',
    ];
.....
}

Install the Filament Panel Builder by running

php artisan filament:install --panels

You can update App\Providers\Filament\AdminPanelProvider with:

            ->login(\Kgalanos\FilamentUser\Filament\Pages\Auth\Login::class)
            ->registration(\Kgalanos\FilamentUser\Filament\Pages\Auth\Register::class)
            ->passwordReset()
            ->profile(\Kgalanos\FilamentUser\Filament\Pages\Auth\EditProfile::class)

            ->discoverPages(base_path('vendor/kgalanos/filament-user/src/Filament/Pages'),'Kgalanos\\FilamentUser\\Filament\\Pages')

You can publish the config file with:

php artisan vendor:publish --tag=filament-shield-config
php artisan vendor:publish --tag="filament-user-config"

This is the contents of the published config file:

return [
];

For the Shield

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            \BezhanSalleh\FilamentShield\FilamentShieldPlugin::make()
        ]);
}
php artisan shield:install

If there is no user id DB it ask you to create an admin.

php artisan make:filament-resource User 

change the App\Filament\Resources

class UserResource extends \Kgalanos\FilamentUser\Filament\Resources\UserResource
{

    protected static ?string $model = App\Models\User::class;
    
    public static function form(Form $form): Form
    {
        $form= parent::form($form);
        return $form;
    }

    public static function table(Table $table): Table
    {
        $table=parent::table($table);
        return $table;
    }
}

Optionally you can use Kgalanos\FilamentUser\Filament\Widgets\ApplicationInfoWidget update App\Providers\Filament\AdminPanelProvider with:

            ->widgets([
                Widgets\AccountWidget::class,
//                Widgets\FilamentInfoWidget::class,
                ApplicationInfoWidget::class,
            ])

Optionally, you can publish the views,if you use ApplicationInfoWidget::class you have to publish the views
using

php artisan vendor:publish --tag="filament-user-views"

Usage

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.