diff --git a/src/Auth.php b/src/Auth.php index bbdb5fa..ad7dbdb 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -5,6 +5,7 @@ use Fintech\Auth\Services\AuditService; use Fintech\Auth\Services\FavouriteService; use Fintech\Auth\Services\IpAddressService; +use Fintech\Auth\Services\LoginAttemptService; use Fintech\Auth\Services\OneTimePinService; use Fintech\Auth\Services\PasswordResetService; use Fintech\Auth\Services\PermissionService; @@ -110,11 +111,11 @@ public function ipAddress() } /** - * @return \Fintech\Auth\Services\LoginAttemptService + * @return LoginAttemptService */ public function loginAttempt() { - return app(\Fintech\Auth\Services\LoginAttemptService::class); + return app(LoginAttemptService::class); } //** Crud Service Method Point Do not Remove **// diff --git a/src/Facades/Auth.php b/src/Facades/Auth.php index 62598a6..499600e 100644 --- a/src/Facades/Auth.php +++ b/src/Facades/Auth.php @@ -5,6 +5,7 @@ use Fintech\Auth\Services\AuditService; use Fintech\Auth\Services\FavouriteService; use Fintech\Auth\Services\IpAddressService; +use Fintech\Auth\Services\LoginAttemptService; use Fintech\Auth\Services\OneTimePinService; use Fintech\Auth\Services\PasswordResetService; use Fintech\Auth\Services\PermissionService; @@ -27,7 +28,7 @@ * @method static AuditService audit() * @method static FavouriteService favourite() * @method static IpAddressService ipAddress() - * @method static \Fintech\Auth\Services\LoginAttemptService loginAttempt() + * @method static LoginAttemptService loginAttempt() * // Crud Service Method Point Do not Remove // * * @see \Fintech\Auth\Auth diff --git a/src/Interfaces/LoginAttemptRepository.php b/src/Interfaces/LoginAttemptRepository.php index d67d9f4..982a83d 100644 --- a/src/Interfaces/LoginAttemptRepository.php +++ b/src/Interfaces/LoginAttemptRepository.php @@ -30,15 +30,6 @@ public function list(array $filters = []); */ public function create(array $attributes = []); - /** - * find and update a resource attributes - * - * @param int|string $id - * @param array $attributes - * @return BaseModel - */ - public function update(int|string $id, array $attributes = []); - /** * find and delete a entry from records * diff --git a/src/Models/LoginAttempt.php b/src/Models/LoginAttempt.php index 0384e36..89962d8 100644 --- a/src/Models/LoginAttempt.php +++ b/src/Models/LoginAttempt.php @@ -8,8 +8,8 @@ class LoginAttempt extends BaseModel { - use AuditableTrait; - use SoftDeletes; + use AuditableTrait; + use SoftDeletes; /* |-------------------------------------------------------------------------- @@ -23,7 +23,7 @@ class LoginAttempt extends BaseModel protected $appends = ['links']; - protected $casts = ['login_attempt_data' => 'array', 'restored_at' => 'datetime', 'enabled' => 'bool']; + protected $casts = ['login_attempt_data' => 'array', 'restored_at' => 'datetime']; protected $hidden = ['creator_id', 'editor_id', 'destroyer_id', 'restorer_id']; @@ -38,6 +38,10 @@ class LoginAttempt extends BaseModel | RELATIONS |-------------------------------------------------------------------------- */ + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(config('fintech.auth.user_model', User::class), 'user_id'); + } /* |-------------------------------------------------------------------------- @@ -60,7 +64,6 @@ public function getLinksAttribute() $links = [ 'show' => action_link(route('auth.login-attempts.show', $primaryKey), __('core::messages.action.show'), 'get'), - 'update' => action_link(route('auth.login-attempts.update', $primaryKey), __('core::messages.action.update'), 'put'), 'destroy' => action_link(route('auth.login-attempts.destroy', $primaryKey), __('core::messages.action.destroy'), 'delete'), 'restore' => action_link(route('auth.login-attempts.restore', $primaryKey), __('core::messages.action.restore'), 'post'), ]; diff --git a/src/Repositories/Eloquent/LoginAttemptRepository.php b/src/Repositories/Eloquent/LoginAttemptRepository.php index 942f9bd..b81f297 100644 --- a/src/Repositories/Eloquent/LoginAttemptRepository.php +++ b/src/Repositories/Eloquent/LoginAttemptRepository.php @@ -36,6 +36,15 @@ public function list(array $filters = []) $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); } else { $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('ip', 'like', "%{$filters['search']}%"); + $query->orWhere('mac', 'like', "%{$filters['search']}%"); + $query->orWhere('platform', 'like', "%{$filters['search']}%"); + $query->orWhere('agent', 'like', "%{$filters['search']}%"); + $query->orWhere('address', 'like', "%{$filters['search']}%"); + $query->orWhere('city', 'like', "%{$filters['search']}%"); + $query->orWhere('state', 'like', "%{$filters['search']}%"); + $query->orWhere('country', 'like', "%{$filters['search']}%"); + $query->orWhere('status', 'like', "%{$filters['search']}%"); $query->orWhere('login_attempt_data', 'like', "%{$filters['search']}%"); } } @@ -45,6 +54,10 @@ public function list(array $filters = []) $query->onlyTrashed(); } + if (!empty($filters['user_id'])) { + $query->where('user_id', '=', $filters['user_id']); + } + //Handle Sorting $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); diff --git a/src/Services/LoginAttemptService.php b/src/Services/LoginAttemptService.php index 1869668..b779b7b 100644 --- a/src/Services/LoginAttemptService.php +++ b/src/Services/LoginAttemptService.php @@ -16,8 +16,8 @@ class LoginAttemptService * LoginAttemptService constructor. * @param LoginAttemptRepository $loginAttemptRepository */ - public function __construct(LoginAttemptRepository $loginAttemptRepository) { - $this->loginAttemptRepository = $loginAttemptRepository; + public function __construct(private readonly LoginAttemptRepository $loginAttemptRepository) + { } /** @@ -40,11 +40,6 @@ public function find($id, $onlyTrashed = false) return $this->loginAttemptRepository->find($id, $onlyTrashed); } - public function update($id, array $inputs = []) - { - return $this->loginAttemptRepository->update($id, $inputs); - } - public function destroy($id) { return $this->loginAttemptRepository->delete($id);