Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Renew Password Laravel Package

yebor974/filament-renew-password

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require yebor974/filament-renew-password
    

    (Use ^2.0 for Filament v3, ^3.0 for Filament v4/v5).

  2. Publish Migrations:

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

    Skippable if you manually add last_renew_password_at (timestamp) and force_renew_password (boolean) to your users table.

  3. Register Plugin: Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \Yebor974\FilamentRenewPassword\FilamentRenewPasswordPlugin::make(),
            ]);
    }
    
  4. First Use Case:

    • Users with force_renew_password = true will be prompted to reset their password on next login.
    • Configure renewal intervals via config/filament-renew-password.php (default: 90 days).

Implementation Patterns

Core Workflows

  1. Recurring Renewal:

    • Triggered via middleware (RenewPasswordMiddleware) or manually in controllers.
    • Example: Check renewal status in app/Http/Middleware/CheckPasswordRenewal.php:
      use Yebor974\FilamentRenewPassword\Facades\RenewPassword;
      
      public function handle(Request $request, Closure $next)
      {
          if (RenewPassword::shouldRenew($request->user())) {
              return redirect()->route('filament.pages.auth.login');
          }
          return $next($request);
      }
      
  2. Force Renewal:

    • Set force_renew_password = true via:
      $user->force_renew_password = true;
      $user->save();
      
    • Overrides recurring logic.
  3. Custom Criteria:

    • Extend Yebor974\FilamentRenewPassword\Contracts\RenewPasswordCriteria:
      class CustomCriteria implements RenewPasswordCriteria
      {
          public function shouldRenew(User $user): bool
          {
              return $user->role === 'admin' && $user->last_login_at->diffInDays() > 30;
          }
      }
      
    • Register in config/filament-renew-password.php:
      'criteria' => [
          \App\CustomCriteria::class,
      ],
      
  4. Integration with Filament Pages:

    • Use the built-in RenewPasswordPage:
      use Yebor974\FilamentRenewPassword\Pages\RenewPasswordPage;
      
      RenewPasswordPage::make()->navigationIcon('heroicon-o-key');
      

Advanced Patterns

  • Bulk Actions: Update multiple users via a Filament resource action:

    use Yebor974\FilamentRenewPassword\Facades\RenewPassword;
    
    public static function getBulkActions(): array
    {
        return [
            BulkAction::make('forceRenew')
                ->action(function (Collection $records) {
                    RenewPassword::forceRenew($records);
                })
                ->label('Force Renew Password'),
        ];
    }
    
  • Conditional Logic: Combine with Filament’s policy system:

    public function canAccess(Page $page): bool
    {
        return parent::canAccess($page) &&
               !RenewPassword::shouldRenew(auth()->user());
    }
    

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If users table already has last_renew_password_at, skip publishing migrations to avoid errors.
    • Fix: Manually add columns or use --force with migrations.
  2. Caching Issues:

    • Renewal checks may cache user data. Clear cache after bulk updates:
      php artisan cache:clear
      
  3. Middleware Order:

    • Place RenewPasswordMiddleware before Authenticate middleware to avoid redirect loops.
    • Example (in app/Http/Kernel.php):
      'web' => [
          \Yebor974\FilamentRenewPassword\Http\Middleware\RenewPasswordMiddleware::class,
          \App\Http\Middleware\Authenticate::class,
          // ...
      ],
      
  4. Timezone Mismatches:

    • Ensure last_renew_password_at uses the same timezone as your app (configured in .env).
    • Debug: Log the diff:
      \Log::debug('Renewal diff:', [
          'days' => now()->diffInDays($user->last_renew_password_at),
          'tz' => now()->timezone,
      ]);
      

Debugging

  • Check Renewal Status:
    \Yebor974\FilamentRenewPassword\Facades\RenewPassword::shouldRenew($user);
    
  • Log Criteria: Enable debug mode in config/filament-renew-password.php:
    'debug' => env('FILAMENT_RENEW_PASSWORD_DEBUG', false),
    
    Outputs criteria evaluation to Laravel logs.

Extension Points

  1. Custom Renewal Page: Extend RenewPasswordPage:

    namespace App\Filament\Pages;
    
    use Yebor974\FilamentRenewPassword\Pages\RenewPasswordPage as BasePage;
    
    class CustomRenewPasswordPage extends BasePage
    {
        protected static string $view = 'filament-renew-password::pages.custom-renew';
    }
    
  2. Email Notifications: Override the mailer service in config:

    'mailer' => \App\Services\CustomRenewPasswordMailer::class,
    

    Implement Yebor974\FilamentRenewPassword\Contracts\RenewPasswordMailer.

  3. Database Columns: Customize columns via service provider:

    public function boot()
    {
        $this->app->bind(
            \Yebor974\FilamentRenewPassword\Contracts\RenewPasswordModel::class,
            function () {
                return new class extends \Yebor974\FilamentRenewPassword\Models\RenewPasswordModel {
                    protected $table = 'custom_users';
                    public $timestamps = false;
                };
            }
        );
    }
    

Performance Tips

  • Batch Updates: Use chunking for large user bases:
    User::chunk(100, function ($users) {
        RenewPassword::forceRenew($users);
    });
    
  • Lazy Evaluation: Defer renewal checks until needed (e.g., in Filament’s canAccess):
    if (RenewPassword::shouldRenew(auth()->user())) {
        return redirect()->route('filament.pages.renew-password');
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui