phpsa/filament-password-reveal
Installation: Add the package via Composer:
composer require phpsa/filament-password-reveal
Publish assets (if needed): Run:
npm run dev
(Ensure your Filament project’s assets are compiled.)
First Use Case:
Replace a standard TextInput with Password in a Filament form:
use Phpsa\FilamentPasswordReveal\Password;
Password::make('password')
->label('New Password')
->required()
->autocomplete('new-password');
Usage section for method signatures and defaults.Password.php for all available methods and their logic.password.blade.php to understand the UI structure and how icons/buttons are rendered.Basic Password Field:
Password::make('password')
->label('Confirm Password')
->rules(['required', 'confirmed']);
Revealable Password (Toggle Visibility):
Password::make('api_token')
->revealable() // Default: true
->showIcon('heroicon-m-eye') // Customize icons
->hideIcon('heroicon-m-eye-slash');
Closure to dynamically enable/disable:
->revealable(fn ($record) => $record->isAdmin)
Copy-to-Clipboard:
Password::make('database_password')
->copyable()
->copyIcon('heroicon-o-copy');
->copyable(fn ($record) => auth()->user()->can('view-secrets'))
Password Generation:
Password::make('generated_password')
->generatable()
->passwordLength(16)
->passwordUsesNumbers(true)
->passwordUsesSymbols(true);
created hook in Filament).Filament Forms/Tables:
Use within Filament\Forms\Form or Filament\Tables\Table components. Example:
public static function form(Form $form): Form
{
return $form
->schema([
Password::make('password')
->generatable()
->copyable(),
]);
}
Custom Styling: Override the Blade template or use Filament’s CSS utilities:
Password::make('password')
->extraAttributes(['class' => 'custom-password-class']);
Localization:
Translate labels/icons via Filament’s getLabel() or getIcon() methods, or override the Blade template.
Testing: Test reveal/copy/generate functionality with:
$this->get('/admin/resource/edit/1')
->assertSee('heroicon-o-eye') // Reveal icon
->press('Copy') // Simulate clipboard action
->assertSessionHas('copied');
Asset Compilation:
npm run dev after installation may break the toggle/copy/generate buttons.resources/js/app.js includes the package’s JS (check the source).Icon Conflicts:
heroicon-o-eye) without importing them in your Filament project’s assets.resources/js/app.js:
import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline';
Conditional Logic:
revealable(), copyable(), or generatable() may not update dynamically if the underlying data changes (e.g., user role).livewire reactivity or refresh the component:
->revealable(fn () => auth()->user()->can('toggle-passwords'))
Password Generation Security:
rules():
Password::make('password')
->generatable()
->rules(['min:12', 'regex:/[A-Z]/', 'regex:/[0-9]/']);
Clipboard Permissions:
{{ dd($value) }} for debugging.password-revealed or password-copied events in your Livewire component:
protected $listen = ['password-revealed' => 'handlePasswordRevealed'];
Custom Templates:
Override the Blade template at resources/views/vendor/filament-password-reveal/components/password.blade.php.
Add New Features:
Extend the Password class to add methods (e.g., pasteable()):
// app/Filament/Extensions/PasswordExtension.php
namespace App\Filament\Extensions;
use Phpsa\FilamentPasswordReveal\Password as BasePassword;
class PasswordExtension extends BasePassword
{
public function pasteable(bool $condition = true): static
{
return $this->customAttributes(['data-pasteable' => $condition]);
}
}
Then register it in AppServiceProvider.
Alpine.js Integration: Use Alpine to add interactivity (e.g., auto-reveal on focus):
Password::make('password')
->extraAttributes([
'x-data' => '{ reveal: false }',
'x-on:focus' => 'reveal = true',
'x-bind:type' => 'reveal ? "text" : "password"',
]);
Validation Hooks:
Use Filament’s afterStateUpdated to validate generated passwords:
Password::make('password')
->generatable()
->afterStateUpdated(fn (set, $state) => $state === 'generated' && $this->validatePassword($state));
How can I help you explore Laravel packages today?