| 1234567891011121314151617181920212223242526272829 |
- <?php
- namespace App\Services;
- use App\Models\UserAccessLog;
- use Illuminate\Pagination\LengthAwarePaginator;
- class UserAccessLogService
- {
- public function getAllPaginated(array $filters = [], int $perPage = 10): LengthAwarePaginator
- {
- $query = UserAccessLog::with(['user:id,name,type'])
- ->orderBy('accessed_at', 'desc');
- if (!empty($filters['type'])) {
- $query->whereHas('user', fn($q) => $q->where('type', $filters['type']));
- }
- if (!empty($filters['date_from'])) {
- $query->whereDate('accessed_at', '>=', $filters['date_from']);
- }
- if (!empty($filters['date_to'])) {
- $query->whereDate('accessed_at', '<=', $filters['date_to']);
- }
- return $query->paginate($perPage);
- }
- }
|