Skip to content

Commit

Permalink
Adds the password expiry when the user is created
Browse files Browse the repository at this point in the history
  • Loading branch information
mwakalingajohn committed Jul 17, 2024
1 parent 692383d commit c319c49
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Concerns/HasPasswordExpiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ trait HasPasswordExpiry
{
public static function bootHasPasswordExpiry()
{

// check if both required columns exist in the database
if (!Schema::hasColumn(config('password-expiry.table_name'), config('password-expiry.column_name'))) {
throw new ColumnsNotFoundException(__('password-expiry::password-expiry.reset-password.exceptions.column_not_found', [
'column_name' => config('password-expiry.column_name'),
'password_column_name' => config('password-expiry.password_column_name'),
'table_name' => config('password-expiry.table_name'),
]));
}

static::created(function ($model) {
if(
$model->wasChanged(config('password-expiry.password_column_name')) &&
filled($model->{config('password-expiry.password_column_name')})
) {
$model->{config('password-expiry.column_name')} = now()->addDays(config('password-expiry.expires_in'));
$model->save();
}
});
}
}

0 comments on commit c319c49

Please sign in to comment.